antonioalopezfernandez
antonioalopezfernandez

Reputation: 383

SQL Server: Order by first characters, then rest of the string

I need some help with a SQL Server query. The table has some kind of field like the following ones:

100
101
102
101/100
101/101

I'd want to sort them to look like this:

100
101
101/100
101/101
102

How can I solve this? Thanks in advance, regards.

Upvotes: 0

Views: 133

Answers (1)

Randy Minder
Randy Minder

Reputation: 48402

You don't give any details on data types and the characteristics of the data. However, based on what you did say, this should work. This will order the data on the first three characters of the column.

Select *
From MyTable
Order By Left(MyColumn,3)

Upvotes: 2

Related Questions