sql server - Checking if multiple entries exist in SQL, delet them and add a new one -


i have table column rowid, personid, activitytypeid, groupid, select above column , works fine.

bit of above table data above data can have data like, same `personid can have multiple activitytypeid , activitytypeid have groupid. this

rowid  personid activitytypeid groupid 1       20          1             2 2       20          2             2 3       20          7             8 

now problem is, if particular personid, there more 3 entries in same group. wish delete entries of person while selecting , add new 1 manually. can done in store procedure?

any appreciated.

apologies, if title doesnt make sense.

a stored procedure way go since making multiple calls different tables.

to clear, trying delete entries based on specific personid , add 1 select statement? can done following syntax:

create proc my_sp  @deletedid int, -- id of person trying delete @insertedid int -- id of person trying add begin set nocount on -- ensure select statement not interefered  delete table personid = @deletedid  insert table select * table2 personid = @insertedid end 

to call stored procedure use execute statement parameters:
exec my_sp 0123, 5555 0123 id of deleted person , 5555 added one.

if wanted manually pass data insert into instead of using select statement you'll have add more parameters , use

insert table values(@param1, @param2, @param3, ... etc) 

here's link on using insert into may well: http://www.w3schools.com/sql/sql_insert.asp


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -