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 2008 Forums
 Transact-SQL (2008)
 order by a varchar field

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2014-12-08 : 23:22:25
Hi friends , I have a table with field called Duration
with values 0-2
4-6
2-4

I 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 data
declare @sample table(id int, Duration varchar(255))
insert @sample(id,Duration)
select 1, '0-2' union all
select 2, '4-6' union all
select 3, '2-4'

-- the select with order by
select * from @sample order by Duration

-- result
-- id Duration
-- ----------- ---------
-- 1 0-2
-- 3 2-4
-- 2 4-6

-- (3 row(s) affected)



Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -