0

I have below table in SQL:

ID  uniquecol   version

1   test        4.4.552.14          
2   test        4.4.554             
3   test        4.4.543.11          

Need output like as below:

test, 1,2,3, 4.4.552.14,4.4.554, 4.4.543.11
shrek
  • 887
  • 6
  • 12
DRas
  • 1
  • 2

1 Answers1

0
SELECT UNIQUECOL, LISTAGG(ID,',') WITHIN GROUP (ORDER BY ID) AS COL2,
LISTAGG(VERSION,',') WITHIN GROUP (ORDER BY ID) AS COL3
FROM t1
GROUP BY UNIQUECOL;

Output -

UNIQUECOL   COL2    COL3
test        1,2,3   4.4.552.14,4.4.554,4.4.543.11
shrek
  • 887
  • 6
  • 12
  • Thanks Shrek, But i am getting below error. 'LISTAGG' is not a recognized built-in function name. I am using SQL server 2005 and 2008 R2. Also i want the output like, each cell to become one column. So in the above case, the output should be 7 columns. (test, 1,2,3, 4.x, 4.x,4.x) – DRas May 25 '18 at 03:57