JayEff
09-11-2003, 03:54 PM
Hi,
Does anybody can help me with this statement. I am getting an 'Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'BEGIN'. error.
The 2 query are running perfectly except when I am putting them togheter in a simple If ...end statement. I have never used a 'If statement' in SQL, that is why I am asking. Is there a special way to put parentheses
I have tried a lot of variants like putting parentheses in the front of Select statement and at the end of the statement, but it is not working. Can we used 'if...else...endif' statement like without the BEGIN keyword?
Here's the query :
IF (SELECT SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order))
FROM tbl_order CCA
WHERE LEN(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)))) < 6
BEGIN
SELECT RIGHT(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)), 4)
FROM tbl_order CCA
WHERE LEN(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)))) < 6
END
Thanks
Does anybody can help me with this statement. I am getting an 'Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'BEGIN'. error.
The 2 query are running perfectly except when I am putting them togheter in a simple If ...end statement. I have never used a 'If statement' in SQL, that is why I am asking. Is there a special way to put parentheses
I have tried a lot of variants like putting parentheses in the front of Select statement and at the end of the statement, but it is not working. Can we used 'if...else...endif' statement like without the BEGIN keyword?
Here's the query :
IF (SELECT SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order))
FROM tbl_order CCA
WHERE LEN(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)))) < 6
BEGIN
SELECT RIGHT(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)), 4)
FROM tbl_order CCA
WHERE LEN(SUBSTRING(CCA.order, PATINDEX('%[^0]%', CCA.order), LEN(CCA.order)))) < 6
END
Thanks