1
How would it be possible to do with what in SQL Server when confronting a table that stores the status records of a given code with a virtual table of the period (Calendar of days) it brings me all the codes that are missing on those given days
For example my table keeps only valid records
DATA - COD - STATUS
01/07/2018 - 123456 - Ok
01/07/2018 - 987654 - Ok
02/07/2018 - 123456 - Ok
03/07/2018 - 123456 - Ok
04/07/2018 - 987654 - OK
05/07/2018 - 987654 - OK
06/07/2018 - 123456 - Ok
08/07/2018 - 987654 - OK
09/07/2018 - 123456 - Ok
09/07/2018 - 987654 - Ok
10/07/2018 - 123456 - Ok
It would be possible to get the following result by Select where bring me the days that are missing for example?
DATA - COD - STATUS
01/07/2018 - 123456 - Ok
01/07/2018 - 987654 - Ok
02/07/2018 - 123456 - Ok
02/07/2018 - 987654 - Fail
03/07/2018 - 123456 - Ok
03/07/2018 - 987654 - Fail
04/07/2018 - 123456 - Fail
04/07/2018 - 987654 - OK
05/07/2018 - 123456 - Fail
05/07/2018 - 987654 - OK
06/07/2018 - 123456 - Ok
06/07/2018 - 987654 - Fail
07/07/2018 - 123456 - Fail
07/07/2018 - 987654 - Fail
08/07/2018 - 123456 - Fail
08/07/2018 - 987654 - OK
09/07/2018 - 123456 - Ok
09/07/2018 - 987654 - Ok
10/07/2018 - 123456 - Ok
10/07/2018 - 987654 - Fail
Complement - 30/07/2018
SELECT B.COD, B.DATA, B.[E] ENTRADA, B.[S] SAIDA
FROM (SELECT P.COD, P.DATA, P.TPMARCA, P.HORA
FROM PREG P
WHERE P.DATA BETWEEN '20180701' AND '20180715'
AND P.COD = '003100'
AND P.TPMC <> 'D'
AND P.REP <> ' '
) A
PIVOT (SUM(A.HORA)
FOR A.TPMARCA IN ([E], [S])) AS B
This is my SELECT and this is the result of it
COD DATA ENTRADA SAIDA
003100 20180701 6,53 19,13
003100 20180702 7,18 18,03
003100 20180706 6,54 19,06
003100 20180707 6,34 13,08
003100 20180708 7,18 NULL
003100 20180709 NULL 18,9
003100 20180712 6,48 18,43
003100 20180714 7,02 18,11
But the result I need is
COD DATA ENTRADA SAIDA
003100 20180701 6,53 19,13
003100 20180702 7,18 18,03
003100 20180705 NULL NULL
003100 20180706 6,54 19,06
003100 20180707 6,34 13,08
003100 20180708 7,18 NULL
003100 20180709 NULL 18,9
003100 20180710 NULL NULL
003100 20180711 NULL NULL
003100 20180712 6,48 18,43
003100 20180713 NULL NULL
003100 20180714 7,02 18,11
003100 20180715 NULL NULL
I mean, I need you to bring back the days that don’t exist
Is that so? https://answall.com/questions/62925/not-in-ou-not-exists-qual-use
– Marconi