首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

更新操作,求救,该怎么处理

2012-01-30 
更新操作,求救这是写在insert触发器中的操作declare@tempTabletable(SnTintidentity(1,1),maxSnint,Snint,

更新操作,求救
这是写在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

热点排行