//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]
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:
Post a Comment