Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sort order

Author  Topic 

nic
Posting Yak Master

209 Posts

Posted - 2003-02-10 : 12:22:10
Hi,
I need to return the values of a column in a particular order. The column is a varchar and has values like:
"10/25"
"10/50"
"25/25"
"25/50"
"100/10"
"100/50"

I need to sort them in the order as displayed but since they are varchars the "100" items would sort before the "25". Somehow I need to break the value apart and sort by the first integer and then by the second int value. I'm not sure how to do this.

Any help would be appreciated.

Nic

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-10 : 12:32:25
SELECT * FROM myTable
ORDER BY CAST(SubString(myCol, 1, CharIndex('/', myCol) AS int),
CAST(SubString(myCol, CharIndex('/', myCol)+1, 99) AS int)


Something like that should work.

Go to Top of Page
   

- Advertisement -