About Narendra Patel

Narendra Patel is Jr. Software Engineer & working on Windows.NET Platform.
Website: http://www.webtechminer.com
Narendra has written 1 article so far, you can find it below.

SQL Order by string And Number

Order By clause is used to order a number or string of any column of SQL.

We can esaily order any column if it;s data-type is INTEGER.Suppose we have column contain data like 2A,1,4,3B,11,111 in VARCHAR column and need to order this column.So below SQL tutorial is about Order by String and number in SQL Server & MS Access.

I have created table & inserts data using Case Statement in SQL. Now I am adding column Quality & assigning some values as under.

After executing above script,you can get below table.

You can use Update multiple rows in SQL to update multiple rows with different values in a single query.


After that,I want to sort Quality column, so I use query as we normally use.!

It gives me below result.


Now,From table you can see that row having Quality=2 comes after Quality=111.That is wrong.
As column is containing some character values,you can’t convert column to int.
So, I have used below query to sort column based on numeric & string.

For SQL Server

After executing,I got below result.!


For MS Access

We can use IIF Function for Access because it does not support Replicate Function