---------------table valued parameters-----------------
Create table xx(id int identity primary key, name varchar(10),gender bit)
CREATE TYPE [dbo].xx_type AS TABLE(
id int , name varchar(10),gender bit,isModified bit
)GO insert into xx select 'c',1
declare @my_type xx_type
insert into @my_type
select *,0 as isModified from xx
update @my_type set name='cc',ismodified=1 where id=3
insert into @my_type select 0,'d',1,0 -- is modified should be zero for newly inserted records
insert into @my_type select 0,'e',1,0 -- is modified should be zero for newly inserted records
exec USP_XX_Modify @my_type
Create PRoc USP_XX_Modify(@my_type xx_type readonly) AS
BEGIN -- updating modified recordsupdate At set name=t.name , gender=t.gender
from @my_type t inner join xx AT on t.id=at.id
where isModified=1
-- inserting newly passed recordsInsert into xx
select name,gender from @my_type where id=0
END select * from xx
CREATE TYPE [dbo].xx_type AS TABLE(
id int , name varchar(10),gender bit,isModified bit
)GO insert into xx select 'c',1
declare @my_type xx_type
insert into @my_type
select *,0 as isModified from xx
update @my_type set name='cc',ismodified=1 where id=3
insert into @my_type select 0,'d',1,0 -- is modified should be zero for newly inserted records
insert into @my_type select 0,'e',1,0 -- is modified should be zero for newly inserted records
exec USP_XX_Modify @my_type
Create PRoc USP_XX_Modify(@my_type xx_type readonly) AS
BEGIN -- updating modified recordsupdate At set name=t.name , gender=t.gender
from @my_type t inner join xx AT on t.id=at.id
where isModified=1
-- inserting newly passed recordsInsert into xx
select name,gender from @my_type where id=0
END select * from xx
No comments:
Post a Comment