Friday, June 3, 2016

Use Stuff in SQL Server

//stuff keyword example

DECLARE @cols AS NVARCHAR(MAX);


SELECT @cols = STUFF((SELECT Distinct '],[' +
columnName
 FROM TableName
 FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
, 1, 1, '')+']';

SELECT @cols

O/P:=Fro Exmple ==>,[Apr-16],[Mar-16]

No comments: