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)
 Help With Tables

Author  Topic 

nhaas
Yak Posting Veteran

90 Posts

Posted - 2007-02-14 : 16:13:40
I am designing a couple tables to track DID blocks(Phone Numbers). I want to track to see if the individual numbers are being used. So if I have a block with numbers 1000 through 1999 and only numbers 1990 and 1991 are used I don’t want to put all 1000 numbers in a table (like we currently have). My question is should this be set up like this?

Table 1(available.,ie DialPlan)
StartNumber,EndNumber

Table 2(Used)
UsedNumber,AddedDate,ModifiedBy

I am trying to make this as efficient as possible

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-02-14 : 17:32:09
What you could do is create a table-valued function that returns a range of numbers. Here's an example (I have been lazy and used a simple loop to create the numbers, you could do it much more efficiently, but I wanted to just show you the basic idea)

create function NumberBlock(@start int, @end int)
returns @NumberBlockTable table (Number int)
as
begin
while @start <= @end
begin
insert @NumberBlockTable values (@start)
set @start = @start + 1
end
return
end

select *
from NumberBlock(1000, 1999)


So then you could join that with your other table, something like

select * 
from Used
inner join NumberBlock(1000, 1999) as N
on Used.UsedNumber = N.Number
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 03:33:16
The basic idea is right, but a much faster version is available, and named F_TABLE_NUMBER_RANGE.
Please search here at SQLTeam.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-02-15 : 10:34:40
Like I said - "I have been lazy and used a simple loop to create the numbers, you could do it much more efficiently"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 10:55:42
Yeah, I know you did.
I was referring to nhaas.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -