F/-\R//-\Z (8/12/2014)
hiI want Compare two Table data and insert changed field to the third table
who can help me
thanks a lot:-):hehe:
While I suspect that the requirements might possibly need refining, here is my initial interpretation.
😎
USE tempdb;
GO
/*
Select records from the first table that do not match
the second table and insert the results into the
third table.
*/
INSERT INTO dbo.BedriddenBed3
(
[ReferralCode]
,[BedDate]
,[BedTime]
,[BedCode]
,[BedDays]
,[UserCode]
,[ISVirtual]
,[FirstName]
,[LastName]
,[BeneficiaryName]
,[ReferralDate]
)
SELECT
B1.[ReferralCode]
,B1.[BedDate]
,B1.[BedTime]
,B1.[BedCode]
,B1.[BedDays]
,B1.[UserCode]
,B1.[ISVirtual]
,B1.[FirstName]
,B1.[LastName]
,B1.[BeneficiaryName]
,B1.[ReferralDate]
FROM dbo.BedriddenBed1 B1
INNER JOIN dbo.BedriddenBed2 B2
ON B1.ReferralCode = B2.ReferralCode
AND B1.BedDate = B2.BedDate
AND B1.BedTime = B2.BedTime
WHERE B1.[BedCode] <> B2.[BedCode]
OR B1.[BedDays] <> B2.[BedDays]
OR B1.[UserCode] <> B2.[UserCode]
OR B1.[ISVirtual] <> B2.[ISVirtual]
OR B1.[FirstName] <> B2.[FirstName]
OR B1.[LastName] <> B2.[LastName]
OR B1.[BeneficiaryName] <> B2.[BeneficiaryName]
OR B1.[ReferralDate] <> B2.[ReferralDate];