To find the Missing rows
Every CEO should have both ‘SEYT’ and ‘ZZZZ’ records in Acc_Personal. I want to find any CEO record if anyone is missing ‘ZZZZ’ record. See table below.
CREATE TABLE DBO.TMP (CEO VARCHAR(20), Acc_Personal VARCHAR(20), AMT INT, DATEA DATETIME, STAT VARCHAR(1))
INSERT INTO DBO.TMP VALUES (‘10001′,’SEYT’,78, ‘2024-04-09′,’N’
INSERT INTO DBO.TMP VALUES (‘10001′,’ZZZZ’,12, ‘2024-03-09′,’N’
INSERT INTO DBO.TMP VALUES (‘10002′,’SEYT’,45, ‘2024-06-02′,’N’
INSERT INTO DBO.TMP VALUES (‘10002′,’ZZZZ’,55, ‘2024-07-07′,’D’
INSERT INTO DBO.TMP VALUES (‘10003′,’SEYT’,76, ‘2024-08-09′,’N’
INSERT INTO DBO.TMP VALUES (‘10004′,’SEYT’,45, ‘2024-04-02′,’C’
INSERT INTO DBO.TMP VALUES (‘10004′,’ZZZZ’,21, ‘2024-07-09′,’N’
INSERT INTO DBO.TMP VALUES (‘10005′,’SEYT’,57, ‘2024-04-01′,’N’
INSERT INTO DBO.TMP VALUES (‘10006′,’SEYT’,59, ‘2024-04-01′,’B’
INSERT INTO DBO.TMP VALUES (‘10006′,’SEYT’,47, ‘2024-02-01′,’A’
INSERT INTO DBO.TMP VALUES (‘10007′,’SEYT’,59, ‘2024-04-09′,’N’
Desired Output
—————–
CEO Acc_personal AMT DATEA STAT
1003
1005
1007
Every CEO should have both ‘SEYT’ and ‘ZZZZ’ records in Acc_Personal. I want to find any CEO record if anyone is missing ‘ZZZZ’ record. See table below. CREATE TABLE DBO.TMP (CEO VARCHAR(20), Acc_Personal VARCHAR(20), AMT INT, DATEA DATETIME, STAT VARCHAR(1)) INSERT INTO DBO.TMP VALUES (‘10001′,’SEYT’,78, ‘2024-04-09’,’N’INSERT INTO DBO.TMP VALUES (‘10001′,’ZZZZ’,12, ‘2024-03-09’,’N’INSERT INTO DBO.TMP VALUES (‘10002′,’SEYT’,45, ‘2024-06-02’,’N’INSERT INTO DBO.TMP VALUES (‘10002′,’ZZZZ’,55, ‘2024-07-07’,’D’INSERT INTO DBO.TMP VALUES (‘10003′,’SEYT’,76, ‘2024-08-09’,’N’INSERT INTO DBO.TMP VALUES (‘10004′,’SEYT’,45, ‘2024-04-02’,’C’INSERT INTO DBO.TMP VALUES (‘10004′,’ZZZZ’,21, ‘2024-07-09’,’N’INSERT INTO DBO.TMP VALUES (‘10005′,’SEYT’,57, ‘2024-04-01’,’N’INSERT INTO DBO.TMP VALUES (‘10006′,’SEYT’,59, ‘2024-04-01’,’B’INSERT INTO DBO.TMP VALUES (‘10006′,’SEYT’,47, ‘2024-02-01’,’A’INSERT INTO DBO.TMP VALUES (‘10007′,’SEYT’,59, ‘2024-04-09′,’N’ Desired Output—————–CEO Acc_personal AMT DATEA STAT100310051007 Read More