I have the following sql command
DECLARE @cols NVARCHAR (MAX)
SELECT @cols = COALESCE (@cols + ',['+ cast(Month as nvarchar(2))+']' , '['+ Cast(Month as nvarchar(2))+']')
FROM (select distinct Month from Employee WHERE Year*100+Month BETWEEN 201704 and 201712 ) as e
PRINT @cols
The result was
[9],[12],[6],[7],[10],[4],[5],[11],[8]
But I really want it to result in sort order
[4],[5],[6],[7],[8],[9],[10],[11],[12]