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
 SQL Server Development (2000)
 logic help

Author  Topic 

vinothonline
Starting Member

4 Posts

Posted - 2007-06-15 : 03:59:29
If i give a value as 5-9 ,the sp shuld return as 5 rows (5,6,7,8,9)
How to perform this . I need some logic .Plz reply me

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-06-15 : 04:18:33
declare @range varchar(10), @from varchar(5), @to varchar(5)
select @range = '5-9'
SELECT @from = LEFT(@range, 1), @to = RIGHT(@range, 1)

select *
from yourTable
Where yourColumn between @from and @to


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-15 : 05:08:20
If you return only numbers in that range, then you need to use Number table in place of yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-15 : 05:12:24
declare @t varchar(10), @start int, @end int, @delim_pos int
Set @t = '5-9'
Set @delim_pos = Patindex('%-%', @t) --specify whatever delimiter
Set @start = Substring(@t, 1, @delim_pos - 1)
Set @end = Substring(@t, @delim_pos + 1, len(@t))
Select number
from master..spt_values
where name is null and
number between @start and @end


--------------------------------------------------
S.Ahamed
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2007-06-15 : 05:20:43
Hi,

Declare @nos table (i int)
insert @nos
select 5 union all
select 9

select N.Number
from master..spt_values N
Left Join @nos NS on N.Number = NS.i
where N.type = 'P' and N.Number > 4
and N.Number <= 9
order by N.Number
Go to Top of Page
   

- Advertisement -