I am trying to add a record into a table by checking against certain conditions for the existance of record through sql script. I am trying it using Merge Statement. Its not working couldnt tract out where i am going wrong. Can some one help me with this?. Thanks
MERGE Categories As target
USING (
SELECT CategoryKey
From Categories where CategoryName = 'TestName'
) AS source on (source.CategoryKey = target.CategoryKey)
WHEN Not Matched THEN
INSERT VALUES ('TestName');
This’ll do the job: