In this post, “Specific row at the top then sort the rest result set in SQL Server“, we are going to learn that how we can order a result set in a customized way which cannot be achieved using ORDER by Clause in a simple way.
To demonstrate this, let’s create a sample table named as “tbl_Department” and insert some dummy rows in it. Below is the code to create the sample table:
Now, add some sample rows into the table:
Let’s have a look at the table data now:
From this table, we need to extract all rows and columns by ordering them on DeptName column. However, we need to keep “Not Assigned” department name value at the top of the list and then the rest of the department name values should be ordered alphabetically in ascending order. Have a look at the desired output:… More