Order by with variable Coalesce

admin

The SQL Coalesce Function: Handling Null Values | LearnSQL.com

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]
Next Post

What are the Possible Health Benefits of CBD oil UK?

CBD is one of the numerous cannabinoids (compounds) in the marijuana plant. Analysts have been checking out the conceivable remedial employments of CBD. Two of the mixtures in cannabis are delta-9 tetrahydrocannabinol (THC) and CBD. These mixtures have various impacts. Up to this point, THC was the most popular compound […]
What are the Possible Health Benefits of CBD oil UK?