Hire my services

If you would like to hire my services, you can now do so by visiting the following link:

Website Design Darlington

Article Statistics

ArticlesLatest Entry
2121-May-2008

Code Bank Statistics

CategoryTipsLatest Entry
Applications420-Feb-2008
Cache118-Apr-2007
Controls926-Jul-2007
CSS107-Sep-2007
Database428-Aug-2007
Dates128-Aug-2007
Email105-Mar-2007
Files123-Apr-2007
HTML101-Mar-2007
Images226-Mar-2007
Pages115-Oct-2007
Sessions122-Nov-2007
SQL Server1518-Mar-2008
Strings309-May-2007
Skip Navigation LinksHome > Code Bank > SQL Server > Sort a varchar column with embedded numbers

Sort a varchar column with embedded numbers

Summary: An example of how you can sort a varchar column which contains numbers.

Here's some example data:

If you run this, you'll see the following output:

Which is incorrectly sorted as you would expect the STU2 to come before STU11. Here's a method to do this which involves removing the preceding characters and sorted by the resulting integer:

This will now contain the correct results: