0

I need to convert multiple records/rows in a column to a single comma separated values in snowflake. I was using FOR XML in MSSQL SERVER for the same, but I need to do the same in SNOWSQL.

Example - Column-1 with three values A, B, C Column-1 A B C

I need the values concatenated like A,B,C.

Amit
  • 11
  • 2

1 Answers1

1

Please take a look at Snowflake's LISTAGG function:

https://docs.snowflake.com/en/sql-reference/functions/listagg.html

example as follows:

CREATE OR REPLACE TABLE xyz (str varchar(100));
INSERT INTO xyz (str) VALUES ('A'), ('B'), ('C');
SELECT listagg(str, ',') as my_strings FROM xyz;

--results
MY_STRINGS
A,B,C

I hope this helps...Rich

Rich Murnane
  • 2,697
  • 1
  • 11
  • 23