Search

Monday, February 11, 2013

Insert record if not exist

Sometime you may need to insert record in one table if that table does not contain the record. You can use IF to check if something exists (or not), and then act accordingly:


IF NOT EXISTS (SELECT * FROM CustomerMaster WHERE FName = 'Sholo' AND LName = 'Twango')

BEGIN

INSERT INTO 
CustomerMaster 

(FName, LName) 
VALUES 
(
'Sholo', 
'Twango'

END

No comments:

Post a Comment