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 2005 Forums
 Transact-SQL (2005)
 range advice

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2007-12-12 : 07:29:31
Hi

I have a need to somehow create a table where the client enter a number range ex: 456 - 789, how would I create such a table and make those numbers searchable so I can enter a number and see if that number is in the 456-789 range.

Regards

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-12 : 07:35:27
[code]DECLARE @Sample TABLE (LowNo INT, HighNo INT)

INSERT @Sample
SELECT 456, 789 UNION ALL
SELECT 123, 456

DECLARE @Search INT
SET @Search = 600

SELECT *
FROM @Sample
WHERE @Search BETWEEN LowNo AND HighNo[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 07:36:32
Do you want to create a number table with that range?

Declare @t table(n int)
insert into @t(n)
select number from
(
select row_number() over (order by s1.colid) as number
from syscolumns s1 cross join syscolumns s2
) as t where number between 456 and 789
Select n from @t

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 07:37:28
I think I misunderstood the question

Madhivanan

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

magmo
Aged Yak Warrior

558 Posts

Posted - 2007-12-12 : 09:08:37
Hi Peso, worked excellent. Thanks!
Go to Top of Page
   

- Advertisement -