sql - Temp table of numbers that do not exist in another table -
i have table called usednumbers
usednumbers contains number in range of 1 , 9999. numbers can anywhere in range.
i want create temp table #unusednumbers.
so far found code create range of numbers 1 9999. i'm not entirely sure how insert temp table , extract numbers not exist in usednumbers.
;with x ( select top (224) [object_id] sys.all_objects ) select top (9999) n = row_number() on (order x.[object_id]) x cross join x y order n;
i love understand more if help.
you try like:
;with x ( select top (224) [object_id] sys.all_objects ) select top (9999) n = row_number() on (order x.[object_id]) x cross join x y except select num usednumbers order n
Comments
Post a Comment