Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Error in query of combine sum in single query

$
0
0
Hi Chandra,

thank you so much for your quick response...
I tried using the new script , I still encounter the same issue :(. Did I miss out something?

Processing ended because the highlighted statement did not complete successfully

> IF EXISTS ( SELECT 1 FROM PRODDTA.F55SWF WHERE SWADDS in ('LBN', 'SBH')) THEN SELECT SWFYEAR AS FisYear ,SWAC01 AS Agency ,SWADDS AS State ,SWSRP1 AS Brand ,SWSRP2 AS SubBrand ,SWSRP4 AS Range ,SUM(SWC9QTY1) AS JanQty ,SUM(SWC9QTY2) AS FebQty FROM PRODDTA.F55SWF where SWADDS in ('LBN', 'SBH') GROUP BY SWFYEAR, SWAC01, SWADDS, SWSRP1, SWSRP2, SWSRP3, SWSRP4, SWSRP0 ORDER BY (CASE WHEN SWADDS = 'JHR' THEN 1 WHEN SWADDS = 'MLK' THEN 2 ELSE 3 END), State, FisYear DESC, (CASE WHEN SWSRP1 = 'PAL' THEN 1 ELSE 2 END) ELSE SELECT SWFYEAR AS FisYear, SWAC01 AS Agency, SWADDS AS State, SWSRP1 AS Brand, SWSRP2 AS SubBrand, SWSRP4 AS Range, SUM(SWC9QTY1) AS JanQty, SUM(SWC9QTY2) AS FebQty FROM PRODDTA.F55SWF where SWADDS NOT IN ('LBN', 'SBH') GROUP BY SWFYEAR, SWAC01, SWADDS, SWSRP1, SWSRP2, SWSRP3, SWSRP4, SWSRP0 ORDER BY (CASE WHEN SWADDS = 'JHR' THEN 1 WHEN SWADDS = 'MLK' THEN 2 ELSE 3 END), State, FisYear DESC, (CASE WHEN SWSRP1 = 'PAL' THEN 1 ELSE 2 END) END IF

SQL State: 42601
Vendor Code: -199
Message: [SQL0199] Keyword IF not expected. Valid tokens: ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN. Cause . . . . . : The keyword IF was not expected here. A syntax error was detected at keyword IF. The partial list of valid tokens is ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN. This list assumes that the statement is correct up to the unexpected keyword. The error may be earlier in the statement but the syntax of the statement seems to be valid up to this point. Recovery . . . : Examine the SQL statement in the area of the specified keyword. A colon or SQL delimiter may be missing. SQL requires reserved words to be delimited when they are used as a name. Correct the SQL statement and try the request again.

Processing ended because the highlighted statement did not complete successfully

Viewing all articles
Browse latest Browse all 13329

Trending Articles