top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

UPDATE if exists else INSERT in SQL Server 2008

+2 votes
151 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 Google+ Share Button LinkedIn Share Button Multiple Social 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...