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 :: 2nd highest salary in mysql 
Sql :: sql convert xml to text 
Sql :: change column name in sql 
Sql :: sql not equal multiple columns 
Sql :: postgresql extract hour and minutes from timestamp 
Sql :: mysql set id auto increment 
Sql :: mysql trim 
Sql :: find a column in all tables mysql 
Sql :: brew install mysql 8 
Sql :: connectionstring mysql c# 
Sql :: pl/sql loop example 
Sql :: oracle drop temporary table 
Sql :: mysql set password for user 
Sql :: Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates. 
Sql :: postgres float to int 
Sql :: mariadb add foreign key 
Sql :: postgres create extension if not exists 
Sql :: mysql timediff 
Sql :: how to drop a table in mysql 
Sql :: postgresql update auto_increment value 
Sql :: select last row in sql 
Sql :: alter table add multiple foreign key sql 
Sql :: oracle sql select all days between two dates except weekends 
Sql :: call function sql oracle 
Sql :: t-sql drop function if exists 
Sql :: sql find duplicate records in two tables 
Sql :: mysql local password denied 
Sql :: mysql shell clear screen 
Sql :: date format mysql 
Sql :: mysql delete duplicates 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =