Try this:
DECLARE @tmp TABLE (ID INT)
INSERT INTO @tmp (ID)
VALUES(1)
INSERT INTO @tmp (ID)
VALUES(2)
INSERT INTO @tmp (ID)
VALUES(3)
INSERT INTO @tmp (ID)
VALUES(4)
INSERT INTO @tmp (ID)
VALUES(15)
INSERT INTO @tmp (ID)
VALUES(16)
INSERT INTO @tmp (ID)
VALUES(17)
DECLARE @mId INT
SELECT @mId = MAX(ID)
FROM @tmp
;WITH NewIds AS
(
SELECT 1 AS nID
UNION ALL
SELECT nID + 1
FROM NewIds
WHERE nID<@mId
)
SELECT ni.nID
FROM NewIds AS ni
WHERE ni.nID NOT IN (SELECT ID AS nID FROM @tmp)
In above code
CTE[
^] were used.
result:
[EDIT]
By The Way... Bad table design! Please, alter your table, but first read it:
IDENITY[
^]
Example table design:
CREATE TABLE MyTable (ID INT INDENTITY(1,1), Column2 VARCHAR(30), Column3 INT)
[/EDIT]