Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql column values comma separated

SELECT STRING_AGG(columnName,',') from tableName
Comment

sql server: select column values as comma separated string

 DECLARE @SQL AS VARCHAR(8000)
SELECT @SQL = ISNULL(@SQL+',','') + ColumnName FROM TableName
SELECT @SQL
Comment

get comma separated values in sql server

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
Comment

search from comma separated values in sql server

WHERE tablename REGEXP "(^|,)@search(,|$)"
Comment

PREVIOUS NEXT
Code Example
Sql :: sql server current date minus 5 years 
Sql :: An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue. 
Sql :: how to use like in sql 
Sql :: oracle limit rows 
Sql :: oracle sessions_per_user limit 
Sql :: mysql remove only_full_group_by permanently 
Sql :: migrate sql table another database 
Sql :: python mysql query to dataframe 
Sql :: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint 
Sql :: mysql sort by date column 
Sql :: alter database name script 
Sql :: ORA-00903 
Sql :: set column to not null mysql 
Sql :: create unique index postgres 
Sql :: sql server week number 
Sql :: oracle source code 
Sql :: order by sql 
Sql :: copy data from one table column to another table column in sql 
Sql :: sql create table statement 
Sql :: sqlalchemy left join 
Sql :: oracle drop index if exists 
Sql :: sql first character 
Sql :: calculate distance between two latitude longitude postgresql 
Sql :: sql select sum group by id laravel 
Sql :: connect to ssms with python 
Sql :: command line mysql xampp 
Sql :: drop index in sql 
Sql :: mysql delete all except 
Sql :: phpmyadmin password root 
Sql :: oracle show procedures 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =