Tuesday, 1 December 2020

Order the result of a comma separated string generated with STUFF in sql server

 Sql query


DECLARE @Cols nvarchar(max);

SET @Cols = STUFF((SELECT ', ' + QUOTENAME(para_name) FROM t_WQ_Cont_list ORDER BY rpt_seq FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)'),1,1,'')

SELECT @Cols;



///////// Result


 [Cl], [EC], [TDS], [Fe], [pH], [SO4]





No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...