Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi friends , I have a table with field called Durationwith values 0-24-62-4I want to order this field but since its a varchar field not able to do it... how can i achieve this
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2014-12-09 : 08:43:18
There is no problem so far:
-- sample datadeclare @sample table(id int, Duration varchar(255))insert @sample(id,Duration)select 1, '0-2' union allselect 2, '4-6' union allselect 3, '2-4'-- the select with order byselect * from @sample order by Duration-- result-- id Duration-- ----------- ----------- 1 0-2-- 3 2-4-- 2 4-6-- (3 row(s) affected)