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

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -