Insert into where no exist

Ashif Avatar

INSERT INTO dbo.miscDemographics_Relation(miscDemographics_Id,miscDemographics_MasterId,miscDemographics_CreatedDate)

SELECT i.miscDemographics_ID,i.miscDemographics_MasterId,GETDATE() FROM inserted i

–END
WHERE NOT EXISTS (SELECT *
FROM dbo.miscDemographics_Relation mrl
WHERE i.miscDemographics_ID=mrl.miscDemographics_ID
AND ISNULL(i.miscDemographics_MasterId,0)=ISNULL(mrl.miscDemographics_MasterId,0))

Leave a Reply

Your email address will not be published. Required fields are marked *