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

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

jQuery Ajax Render Fragments OR Whole Page -

java - Why is BlockingQueue.take() not releasing the thread? -