DECLARE @SQL AS VARCHAR(8000)
SELECT @SQL = ISNULL(@SQL+',','') + ColumnName FROM TableName
SELECT @SQL
STRING_AGG: Applies to SQL Server 2017 (14.x) and later
DECLARE @Table2 TABLE(ID INT, Value INT);
INSERT INTO @Table1 VALUES (1,100),(1,200),(1,300),(1,400);
SELECT ID , STRING_AGG([Value], ', ') AS List_Output
FROM @Table2
GROUP BY ID;
-- OR
DECLARE @Table1 TABLE(ID INT, Value INT)
INSERT INTO @Table1 VALUES (1,100),(1,200),(1,300),(1,400)
SELECT ID
,STUFF((SELECT ', ' + CAST(Value AS VARCHAR(10)) [text()]
FROM @Table1
WHERE ID = t.ID
FOR XML PATH(''), TYPE)
.value('.','NVARCHAR(MAX)'),1,1,' ') List_Output
FROM @Table1 t
GROUP BY ID
WHERE tablename REGEXP "(^|,)@search(,|$)"
Code Example |
---|
Sql :: update database collation in postgresql |
Sql :: sql and operator |
Sql :: create table |
Sql :: mysql --version |
Sql :: sql constraints |
Sql :: selecting all columns from table sql database |
Sql :: mysql dump database tables only |
Sql :: import database from sql file |
Sql :: like operator in sql |
Sql :: sqlite3.OperationalError: near "7": syntax error |
Sql :: quit mysql |
Sql :: migrations.RunSQL |
Sql :: sql check |
Sql :: sql query interview questions |
Sql :: How to drop table in mysql ? |
Sql :: sql query checker |
Sql :: oracle database status v$logfile |
Sql :: sql examples from framework |
Sql :: install sql |
Sql :: First Step in installing SQL workbench |
Sql :: hive hbase create external table |
Sql :: sql_inner_join |
Sql :: list enums sql |
Sql :: veri girme SQL |
Sql :: alter fedora mysql 8.0 user |
Sql :: how to find shortest and longest name in sql |
Sql :: mysql drop vs delete |
Sql :: sütun güncelleme SQL |
Sql :: mysql grant execute |
Sql :: T-SQL look for records with a hex value in a text field |