Skip to main content
deleted 213 characters in body
Source Link
Kannan Kandasamy
  • 14k
  • 3
  • 28
  • 40

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use STRING_AGG as below:

SELECT id, STRING_AGG(CONCAT(name, ':', [value]), ', ')
FROM #YourTable 
GROUP BY id

•••• And if anyone likes to use this for just aggregate one single column value the code will be like this:

SELECT [id_name], STRING_AGG([col_name], ', ')
FROM [table_name] 
GROUP BY [id_name]

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use STRING_AGG as below:

SELECT id, STRING_AGG(CONCAT(name, ':', [value]), ', ')
FROM #YourTable 
GROUP BY id

•••• And if anyone likes to use this for just aggregate one single column value the code will be like this:

SELECT [id_name], STRING_AGG([col_name], ', ')
FROM [table_name] 
GROUP BY [id_name]

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use STRING_AGG as below:

SELECT id, STRING_AGG(CONCAT(name, ':', [value]), ', ')
FROM #YourTable 
GROUP BY id
I love to use CAPITAL letters when I write SQL syntax it's better for eye-readable.
Source Link

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use string_aggSTRING_AGG as below:

selectSELECT id, string_aggSTRING_AGG(concatCONCAT(name, ':', [value]), ', ')
fromFROM #YourTable 
groupGROUP byBY id

•••• And if anyone likes to use this for just aggregate one single column value the code will be like this:

SELECT [id_name], STRING_AGG([col_name], ', ')
FROM [table_name] 
GROUP BY [id_name]

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use string_agg as below:

select id, string_agg(concat(name, ':', [value]), ', ')
from #YourTable 
group by id

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use STRING_AGG as below:

SELECT id, STRING_AGG(CONCAT(name, ':', [value]), ', ')
FROM #YourTable 
GROUP BY id

•••• And if anyone likes to use this for just aggregate one single column value the code will be like this:

SELECT [id_name], STRING_AGG([col_name], ', ')
FROM [table_name] 
GROUP BY [id_name]
formatting
Source Link
Ashley Medway
  • 7.3k
  • 7
  • 54
  • 73

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use string_aggstring_agg as below:

select id, string_agg(concat(name, ':', [value]), ', ')
    from #YourTable 
    group by id

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use string_agg as below:

select id, string_agg(concat(name, ':', [value]), ', ')
    from #YourTable 
    group by id

If it is SQL Server 2017 or SQL Server Vnext, SQL Azure you can use string_agg as below:

select id, string_agg(concat(name, ':', [value]), ', ')
from #YourTable 
group by id
Source Link
Kannan Kandasamy
  • 14k
  • 3
  • 28
  • 40
Loading