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
 Transact-SQL (2000)
 Finding Gaps

Author  Topic 

BigRetina
Posting Yak Master

144 Posts

Posted - 2003-04-07 : 06:56:44
Salute..
How can I write a select statement to find the gap in a serialized column such as :
InvoiceNo
---------
1
2
3
5
9

I want to return the following:
Gaps:
------
4
6
7
8

Thanks In Advance

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-04-07 : 07:11:14

select
n.n
from
dbatoolbox.dbo.numbers n
where
not exists (
select 1
from
BigRetina
where
n.n <> InvoiceNo )

 
dbatoolbox.dbo.numbers is a tally table with ints from 1 to whatever.

Jay White
{0}
Go to Top of Page

Peter Dutch
Posting Yak Master

127 Posts

Posted - 2003-04-07 : 07:13:39
http://www.nigelrivett.com/



EDIT
sorry, forgot to refresh...
/EDIT

Edited by - Peter Dutch on 04/07/2003 07:15:18
Go to Top of Page
   

- Advertisement -