更新操作,求救
这是写在insert触发器中的操作
declare @tempTable table
(SnT int identity(1,1),maxSn int,Sn int,rowguid uniqueidentifier)
insert into @tempTable(maxSn,rowguid)
select 2,rowguid from inserted
update @tempTable set Sn=maxSn+SnT
上面一部分是没有问题的
------------------------------------
关键:如何更新 收银付表01 中的Sn = @tempTable的sn
关联字段是rowguid
下面是写的错的,大概就是这个意思
update 收银付表01 set Sn=(select Sn from @tempTable where @tempTable.rowguid=收银付表01.rowguid)
where rowguid in(select rowguid from @tempTable)
------解决方案--------------------這麼寫的
Update A Set Sn = B.Sn From 收银付表01 A Inner Join @tempTable B On A.rowguid = B.rowguid
------解决方案--------------------update 收银付表01 set Sn=t.Sn
from @tempTable t,收银付表01 a
where t.rowguid=a.rowguid
------解决方案--------------------或者
Update A Set Sn = B.Sn From 收银付表01 A, @tempTable B Where A.rowguid = B.rowguid
------解决方案--------------------update @tempTable a set a.Sn=b.maxSn + b.SnT from @tempTable b where a.rowguid = b.rowguid