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)
 Record ID

Author  Topic 

golden_manish
Starting Member

13 Posts

Posted - 2003-09-14 : 11:23:31
Hello Friends,

I am manish from India.
I have a small question, for you.
How can i find out, if there are any missing records in a table.
Ex. There is a Table with 10 Records.
Records - (Primary Key) 1,2,3,4,5,6,8,9 and 10 are in the table.
How can i find out, the fastet way that Record No 7 is missing.

Thanks friends.

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2003-09-14 : 12:50:54
A good way to do this is build a temp table of numbers containing your min and max id's and do an outer join of this numbers table with your table. Null rows in your table indicate a gap at certain numbers. If you need more information, please ask.

Sarah Berger MCSD
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-09-14 : 16:39:36
see
http://www.nigelrivett.net/FindGapsInSequence.html


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-14 : 17:27:30
Take a look at this one, too:

SELECT x.Value as GapStart, Max(y.value) AS GapEnd
FROM Vals y
INNER JOIN Vals x
ON y.Value < x.value
GROUP BY x.Value
HAVING Max(y.Value) <> x.value - 1

- Jeff
Go to Top of Page
   

- Advertisement -