Thursday, August 28, 2008

Finding missing sequence values in sql server

Recently while troubleshooting a problem, I had the need to identify missing rows from a table with an identity column.

There is always the simple way of joining to a lookup table with all of the possible values, and then search where the value appears in the lookup table, and not in your source table.

However, a quick google found this blog post, that has some great examples, and a fairly complete analysis of the different alternatives.

How to find missing values in a sequence with SQL

1 comment:

Antonio Yon said...

This is one of the more elegant pieces of code I've encountered recently.