Then sort by them, like
DECLARE @cols NVARCHAR (MAX)
SELECT @cols = COALESCE (@cols + ',[' + sMonths + ']', '[' + sMonths + ']')
FROM (SELECT DISTINCT sMonths, sYearN, sMonthN FROM tbl_TempSalesRepSales) AS PV
ORDER BY PV.sYearN, PV.sMonthN
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Everyone,
below is my code
DECLARE @cols NVARCHAR (MAX)
SELECT @cols = COALESCE (@cols + ',[' + sMonths + ']',
'[' + sMonths + ']')
FROM (SELECT DISTINCT sMonths FROM tbl_TempSalesRepSales) PV
ORDER BY sMonths
result:
[Aug20],[Dec20],[Feb21],[Jan21],[Nov20],[Oct20],[Sep20]
i want in order bleow
[Aug20],[Sep20],,[Oct20],[Nov20][Dec20],[Jan21],[Feb21]
Thanks & Regards
Hitesh Patel
Then sort by them, like
DECLARE @cols NVARCHAR (MAX)
SELECT @cols = COALESCE (@cols + ',[' + sMonths + ']', '[' + sMonths + ']')
FROM (SELECT DISTINCT sMonths, sYearN, sMonthN FROM tbl_TempSalesRepSales) AS PV
ORDER BY PV.sYearN, PV.sMonthN
The result/column sMonths is a string and gets sorted alphanumeric;
Do you have and additional information in the table related to a date/mont, so that you could sort by that?