Praveenks
Praveenks

Reputation: 1496

BEGIN..END not working in Nested IF..ELSE

I am confused with the BEGIN.. END in the nested IF..ELSE condition. For example, when I am trying to execute below mentioned query. It is returning an error -- "Incorrect syntax near ElSE.."

IF ( ISNULL(@tin,'')=''AND ISNULL(@prpr_ntwrk,'')<>'' )
BEGIN
    IF (ISNULL(@prpr_ntwrk,'')='P')
    BEGIN
            -- CODE     
    END                         
    ELSE 
    BEGIN
            -- CODE
    END

END

please suggest.

Upvotes: 0

Views: 10912

Answers (2)

jcromanu
jcromanu

Reputation: 1481

Here are my recommendations :

1.-Give more whitespaces in this part of your code so it can be legible and avoid problems.

IF ( ISNULL(@tin,'')=''AND ISNULL(@prpr_ntwrk,'')<>'' )

2.- Insert a new line after the last END

3.- Run everything on terminal with isql because interactive SQL can be buggy sometimes

4.-Post the code between the if and end please.

Hope it helps

Upvotes: 1

John
John

Reputation: 159

The code below executes on ASE 15.7.0

DECLARE @tin varchar, @prpr_ntwrk varchar

IF ( ISNULL(@tin,'')=''AND ISNULL(@prpr_ntwrk,'')<>'' )
BEGIN
    IF (ISNULL(@prpr_ntwrk,'')='P')
    BEGIN
        SELECT "P"
    END                         
    ELSE 
    BEGIN
        SELECT "Not P"
    END
END

Note that ASE gets confused with the empty stubs "-- Code" in the original example.

Your first IF statement may not do what you want, but I am sticking to the question asked.

Upvotes: 1

Related Questions