Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
Please help me to get a comma seprated result. I am using DB2(IBM® Data Studio Version 4.1.0.0)
Below is my query
SQL
SELECT DISTINCT KEY_TMS FROM DBQPUBS.TCLT_BILL  WHERE  DT2_BILL = '2015-02-24';


Updated Question
I tried like this

SQL
SELECT CAST(LISTAGG(KEY_TMS ,',')AS Varchar(255)) FROM DBQPUBS.TCLT_BILL  WHERE  DT2_BILL = '2015-02-24';


But getting an Error
NO AUTHORIZED FUNCTION NAMED LISTAGG HAVING COMPATIBLE ARGUMENTS WAS FOUND. SQLCODE=-440

Thanks in advance
Posted
Updated 31-Mar-15 0:07am
v3

1 solution

This largely depends on which version of DB2 you have available to you

This solution uses LISTAGG[^] if you have DB2 9.7 FP4 or above

If you are using a version that supports variables you could try this[^] (yes I know it's SQL but it should work in DB2 as well)

Or try this from Tom Kyte[^] - it's an Oracle solution, but again should work in DB2
 
Share this answer
 
Comments
jinesh sam 31-Mar-15 6:02am    
I am using IBM® Data Studio Version 4.1.0.0
CHill60 31-Mar-15 6:11am    
Well that's more of an IDE but I think the underlying version of DB2 Express-C will be at least 9.7 so the first option should work for you
jinesh sam 31-Mar-15 6:23am    
I tried with the first one. but showing some error.i have updated the question. please have a look
CHill60 31-Mar-15 6:35am    
Ah - too early a version. Try the 3rd suggestion in my solution (From Tom Kyte)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900