Hi @BKAN
1)Notice that you had this Select Into statement SELECT * FROM EMP INTO #empdata
, which is incorrect. It should be like this: SELECT * INTO #empdata FROM EMP
Refer to this article for more details: SQL SELECT INTO Statement
2) In the below code where can I do an update please help.
Try this:
SELECT * FROM EMP INTO #empdata
SELECT * FROM CUST INTO #custdata
Select t.*,t1.*
From #empdata t Join #custdata t1 On t.custid=t1.custid
Into #totaldata
UPDATE T
SET T.Column1 = U.Column1,T.Column2 = U.Column2
FROM dbo.totaldata T JOIN (select distinct * from #totaldata) AS U ON T.custid = U.custid;
INSERT INTO dbo.totaldata
SELECT U.*
FROM (select distinct * from #totaldata) AS U
WHERE NOT EXISTS (SELECT 1 FROM dbo.totaldata T WHERE T.custid = U.custid);
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.