事务复制时产生的存储过程是否有问题?
对NorthWind 的 Products表做事务复制,在更新了某个字段以后(比如:ReorderLevel),复制过程总是对ProductID也进行更新,导致出现无法更新标示列ProductID的错误,查了以下存储过程,发现是复制过程错误的认为ProductID需要更改,实在郁闷?请高手指教其中的原因。
存储过程是这样的:
create procedure "sp_MSupd_Products"
@c1 int,@c2 nvarchar(40),@c3 int,@c4 int,@c5 nvarchar(20),@c6 money,@c7 smallint,@c8 smallint,@c9 smallint,@c10 bit,@pkc1 int
,@bitmap binary(2)
as
if substring(@bitmap,1,1) & 1 = 1
begin
update "Products" set
"ProductID" = case substring(@bitmap,1,1) & 1 when 1 then @c1 else "ProductID" end
,"ProductName" = case substring(@bitmap,1,1) & 2 when 2 then @c2 else "ProductName" end
,"SupplierID" = case substring(@bitmap,1,1) & 4 when 4 then @c3 else "SupplierID" end
,"CategoryID" = case substring(@bitmap,1,1) & 8 when 8 then @c4 else "CategoryID" end
,"QuantityPerUnit" = case substring(@bitmap,1,1) & 16 when 16 then @c5 else "QuantityPerUnit" end
,"UnitPrice" = case substring(@bitmap,1,1) & 32 when 32 then @c6 else "UnitPrice" end
,"UnitsInStock" = case substring(@bitmap,1,1) & 64 when 64 then @c7 else "UnitsInStock" end
,"UnitsOnOrder" = case substring(@bitmap,1,1) & 128 when 128 then @c8 else "UnitsOnOrder" end
,"ReorderLevel" = case substring(@bitmap,2,1) & 1 when 1 then @c9 else "ReorderLevel" end
,"Discontinued" = case substring(@bitmap,2,1) & 2 when 2 then @c10 else "Discontinued" end
where "ProductID" = @pkc1
if @@rowcount = 0
if @@microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end
else
begin
update "Products" set
"ProductName" = case substring(@bitmap,1,1) & 2 when 2 then @c2 else "ProductName" end
,"SupplierID" = case substring(@bitmap,1,1) & 4 when 4 then @c3 else "SupplierID" end
,"CategoryID" = case substring(@bitmap,1,1) & 8 when 8 then @c4 else "CategoryID" end
,"QuantityPerUnit" = case substring(@bitmap,1,1) & 16 when 16 then @c5 else "QuantityPerUnit" end
,"UnitPrice" = case substring(@bitmap,1,1) & 32 when 32 then @c6 else "UnitPrice" end
,"UnitsInStock" = case substring(@bitmap,1,1) & 64 when 64 then @c7 else "UnitsInStock" end
,"UnitsOnOrder" = case substring(@bitmap,1,1) & 128 when 128 then @c8 else "UnitsOnOrder" end
,"ReorderLevel" = case substring(@bitmap,2,1) & 1 when 1 then @c9 else "ReorderLevel" end
,"Discontinued" = case substring(@bitmap,2,1) & 2 when 2 then @c10 else "Discontinued" end
where "ProductID" = @pkc1
if @@rowcount = 0
if @@microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end
GO