Hi itsme,
Refer below sample query.
SQL
DECLARE @A AS TABLE(ID INT NOT NULL,Status VARCHAR(20) NULL)
INSERT INTO @A VALUES(1,'P')
INSERT INTO @A VALUES(2,'A')
INSERT INTO @A VALUES(3,'P')
DECLARE @B AS TABLE(Status VARCHAR(20) NULL,IDtblA INT NULL,empid INT NULL)
INSERT INTO @B VALUES('A',1,1)
INSERT INTO @B (Status,IDtblA,empid)
SELECT NULL,ID,NULL FROM @A A WHERE A.ID NOT IN (SELECT IDtblA FROM @B)
SELECT * FROM @B
Output
Status |
IDtblA |
empid |
A |
1 |
1 |
|
2 |
|
|
3 |
|