Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL-SSIS. Find missing numbers in table

I'm using ssis 2008 and sql server 2012. I have a table with column FileNumber. I would like to make sure all the numbers are following and there are no wholes. No missing numbers. For example:

FileNumber
--------------
110
111
112
114
115
117

I would like the ssis to output the numbers 113 and 116 which are missing.

Any idea how to do this?

like image 907
Itay.B Avatar asked Apr 28 '26 15:04

Itay.B


1 Answers

Try this:

DECLARE @t table(
 FileNumber int
 );

INSERT INTO @t(FileNumber) VALUES(110), (111), (112), (114), (115), (117);

SELECT t1.FileNumber + 1 AS sequance
FROM @t AS t1
LEFT OUTER JOIN @t AS t2 ON t1.FileNumber + 1 = t2.FileNumber
WHERE t2.FileNumber IS NULL
like image 171
Mahmoud Gamal Avatar answered May 01 '26 06:05

Mahmoud Gamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!