i have 2 tables, one is called TEMP and the other one is called MAIN. So all what i am trying to do is to check if all records from the TEMP table are in the MAIN table. The logic should be all records from temp table must also be in the main table but when i run the sql query here; it does not give me any record and i know there are records missing in the main table from the temp table. what am i doing wrong here?
IF EXISTS(SELECT DISTINCT GRP_NM
,GRP_VAL
FROM TEMP
WHERE GRP_NM + GRP_VAL NOT IN (SELECT GRP_NM + GRP_VAL FROM MAIN)
)
BEGIN
INSERT INTO MAIN(GRP_NM, GRP_VAL )
SELECT GRP_NM
,GRP_VAL
FROM MAIN
WHERE GRP_NM + GRP_VAL NOT IN (SELECT GRP_NM + GRP_VAL FROM MAIN)
END