How to work with this Case Statement
Posted on 2012-09-14
I'm on DB2 UDB 9.7. Probably, this is a very easy one, but i can't seem to work this out.
I have the following Case Statement.
(Case WHEN VAR1 = 'Y' THEN 'TEXT1' ELSE '' END) ||','||
(CASE WHEN VAR2 = 'Y' THEN 'TEXT2' ELSE '' END) ||','||
(CASE WHEN VAR3 = 'Y' THEN 'TEXT3' ELSE '' END) ||','||
(CASE WHEN VAR4 = 'Y' THEN 'TEXT4' ELSE '' END) ||','||
(CASE WHEN VAR5 = 'Y' THEN 'TEXT5' ELSE '' END)
Expected Result : TEXT1,TEXT2,TEXT3,TEXT4,TEXT5
For example, if only TEXT3 is there, then
Expected Result : Text3
When i do the above logic, i'm getting
I don't want to show the commas if the value is not there. How to display that?