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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -