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

Case Statement

$
0
0
Hi All,

Im sure this is very simple
I have a case statement that i am trying to use in order to add another column to my table. The Case statement checks to see if two conditions are true and if they are it adds 1 to a new column.

Column A contains an event. Column B contains freetext of varying descriptions in this case Test 1 Test 2 etc

The Statement is as follows

Code:

SELECT        AL1.A,
                AL1.B,
                AL1.C,
                AL1.D,
                AL1.E,
                AL1.F,
                AL1.G,
                AL1.H,
                AL1.I,
                AL1.J,
                AL1.K,
                AL1.L,
                AL1.M,
                AL1.N,
                AL1.O,               
                CASE        WHEN AL1.A = 'XX' AND AL1.function IN('Test 1','Test 2','Test 3') THEN 1 ELSE 0
                        WHEN AL1.event_cd = 'AD' AND AL1.function IN('Test 1') THEN 1 ELSE 0 END 
                                                                       
FROM                        public."Sample_Table" AL1


The error message is as follows

ERROR: syntax error at or near "WHEN"
LINE 17:

********** Error **********

ERROR: syntax error at or near "WHEN"
SQL state: 42601
Character: 410





Any help would be greatly appreciated

Thanks

Viewing all articles
Browse latest Browse all 13329

Trending Articles