INSERT INTO table3
SELECT Getdate() AS 'reportdate',
table1.gid AS 'gid',
table1.phone AS 'phone',
flag = CASE
WHEN Isnull(table2.phone)
THEN 'N'
ELSE 'Y'
END
FROM table1
LEFT OUTER JOIN table2
ON table1.gid = table2.gid
AND table1.phone = table2.phone
|