top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

UPDATE if exists else INSERT in SQL Server 2008

+2 votes
708 views

In a stored procedure, for the same table i want to UPDATE if exists else INSERT data.
How ca this be implemented?

posted May 9, 2014 by Khusboo

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

IF EXISTS(SELECT * FROM #Table WHERE id='211')
BEGIN
UPDATE #Table SET id = '200' WHERE (id='211')
END
ELSE
BEGIN
INSERT INTO #Table(id)VALUES('211')
END

answer Nov 12, 2014 by Manikandan J
Similar Questions
...