Tag Info

New answers tagged

0

Here is something to get you started. It will return a list with all missing Ids just like requested. No need for other tables. CREATE TABLE Numbers(n INT ) INSERT INTO Numbers SELECT 9001 INSERT INTO Numbers SELECT 9002 INSERT INTO Numbers SELECT 9006 INSERT INTO Numbers SELECT 9007 INSERT INTO Numbers SELECT 9008 INSERT INTO Numbers SELECT 9009 SELECT * ...


7

First create an auxiliary numbers table larger than the maximum range you will ever be interested in. CREATE TABLE dbo.Numbers ( N INT primary key ); WITH E00(N) AS (SELECT 1 UNION ALL SELECT 1), E02(N) AS (SELECT 1 FROM E00 a, E00 b), E04(N) AS (SELECT 1 FROM E02 a, E02 b), E08(N) AS (SELECT 1 FROM E04 a, E04 b), E16(N) AS (SELECT 1 ...



Top 50 recent answers are included