A union of curiosity and data science

Knowledgebase and brain dump of a database engineer

Use a select statement to create a list within a varchar variable

Select a list into a variable. 

SQL array to list. 

create table #demo (ID varchar(8))
insert into #demo (ID) values (1),(2), (3), (4)

DECLARE @cols NVARCHAR(max)   = '';
SELECT   @cols = (@cols + ',' + ID) FROM  #demo fs   
select @cols


Add comment