Regarding to this post and answer: https://stackoverflow.com/a/1389653/9343200
What I'm trying to do is to find missing IDs in table Paragony
then I have to check one more column: par_nrkasy if it's =1 or =2.
I'm trying to add one more condition WHERE par_nrkasy =
but I have no clue how to add to this query, I mean, to make it works and keep the meaning of primary code.
My code:
;WITH Missing (missnum, maxid) AS
(
SELECT
1 AS missnum,
(SELECT MAX(par_numerf)
FROM Paragony)
UNION ALL
SELECT missnum + 1, maxid
FROM Missing
WHERE missnum < maxid
)
SELECT missnum
FROM Missing
LEFT OUTER JOIN Paragony tt ON tt.par_numerf = Missing.missnum
WHERE tt.par_numerf is NULL
OPTION (MAXRECURSION 0);
Any ideas? Anything I tried I got wrong results like duplicates or not results at all
Alternatively I could have use it through this code, but problem is the same how to add clause
SELECT DISTINCT par_numerf + 1
FROM Paragony
WHERE par_numerf + 1 NOT IN (SELECT DISTINCT par_numerf FROM Paragony);