How to Sorting Data in Sql server - Bandi [Resolved]

Posted by Jayakumars under Sql Server on 5/22/2015 | Points: 10 | Views : 362 | Status : [Member] [MVP] | Replies : 1
Hi
Bandi

How to solve this issue for Sorting data


create table #temp(Name varchar(20))
insert into #temp (Name)
select '1523'
union all
select '0-300'
union all
select '110-150'
union all
select '61-230'
union all
select '41-71'
union all
select '81-100'


Select * from #temp

--I need output this
--=====================
0-300
41-71
61-230
81-100
110-150
1523

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 5/25/2015 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Select * from #temp 
order by cast(SUBSTRING ( name, 1, CHARINDEX('-', Name+'-')-1) as int)


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response