Thursday 25 February 2016

Sql server table columns with comma separated string using COALESCE


//Sql Query

DECLARE @ColStr VARCHAR(MAX)
SELECT @ColStr = COALESCE(''+@ColStr +',' ,'') +'['+ name+']' FROM sys.columns where object_name(object_id)='TableName'

Print @ColStr


// Result

 [Active],[StateCode],[StateName]

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...