Wednesday, February 23, 2011

INSERT INTO WHERE NOT EXISTS

-- If @UserID and @ServerID already exists
-- in table [tblSysAdmins], the values
-- will not be inserted

INSERT INTO [tblSysAdmins] ([UserID], [ServerID], [Authorize])
SELECT @UserID, @ServerID, @Authorize
WHERE NOT EXISTS
(SELECT *
FROM tblSysAdmins
WHERE [UserID] = @UserID
AND [ServerID] = @ServerID )

No comments:

Post a Comment