4
You can use the clause WITH
to generate the sequence of number and compare it with the table in question:
WITH sequencias
AS (SELECT 1 AS sequencia
UNION ALL
SELECT s.sequencia + 1 AS sequencia
FROM sequencias s
WHERE s.sequencia <= 5)
SELECT s.*
FROM sequencias s
WHERE NOT EXISTS(SELECT 1
FROM tabela t
WHERE t.nr_volume = s.sequencia)
ORDER BY s.sequencia
OPTION(MAXRECURSION 0);
We have a great command explanation WITH
in answer to the question Using WITH AS command in Sql Server.