sql server - Update or Insert Depending on Whether the Record Already Exists -


i want update "grade" column in "studenttable" clause of "studentid"". , if there no "studentid" found in "studenttable" want insert data instead.

how can this?

you first check if record exists, if perform update, if not exist, means need insert it.

here go:

if exists(select * studenttable studentid = @myid)   begin      --exists perform update     update studenttable set grade = 'a+' studentid=@myid     --other code...   end else   begin     --record not exist insert      insert studenttable(myid, grade) values (@myid, 'a+')     --other code...   end 

Comments

Popular posts from this blog

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

c# - Global Variables vs. ASP.NET Session State -