Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

ORDER BY clause with CASE Expressions(CASE STATEMENT)

ORDER BY clause with CASE Expressions(CASE STATEMENT): 

I was googling some code examples on how to use “ORDER BY clause with CASE Expressions (CASE STATEMENT)”, with some googling information I tried following t-sql code and that worked for me.

This experience I want to share in this post with example and code sample.

Searched CASE expression:

The searched CASE expression evaluates a set of Boolean expressions to determine the result.


In this example searched CASE expression used to decide order, for male all records are in descending order and for female ascending order.

Code sample:

SELECT * FROM dbo.Employee
 CASE WHEN Gender='Male' THEN EmployeeName END Desc,
 CASE WHEN Gender='Female' THEN Country END ASC

Invalid entry,please enter valid data.