Sort Number Column in a custermized way (Use CASE function)


A reader was asking how to sort number of days returned from a datetime function in a custermized way: positively first and then negatively after the postive ones. For example: 22,33,45, -11,-21,-300. It would a easy operation by using CASE statement to generate the sorting order:
 

ORDER BY CASE WHEN ending_in>0 THEN 0 ELSE 1 END,

CASE WHEN ending_in>0 THEN ending_in ELSE 1*ending_in END

Here is the original post: http://forums.asp.net/t/1234313.aspx

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s