读书人

请好手帮忙写个触发器

发布时间: 2014-01-06 15:53:52 作者: rapoo

请高手帮忙写个触发器?

ALTER trigger [dbo].[trd_hwxxupdate]
On [dbo].[Hwxx]
for Update
As
if update(hwzt)
begin
update jydxx
set jydzt='03'
from jydxx br,Deleted d,Inserted i
where br.jydbh = d.jydbh
end

以上是我自己写的一个触发器:意思是当更新hwxx表时 也去更新jydxx表的jydzt=‘03’
现在多了条件就是
当更新hexx表的hwzt=01时 jydzt=01,当hwzt=02 jydzt=02 当hwzt=03 jydzt=03
这个要怎么写?
[解决办法]
引用:
不是把
是hwxx.hwzt='01'时 jydxx.jydzt='01'
hwxx.hwzt='02'时 jydxx.jydzt='02'
hwxx.hwzt='03'时 jydxx.jydzt='03'


你的意思是这样吗:
ALTER trigger [dbo].[trd_hwxxupdate]
On [dbo].[Hwxx]
for Update
As

if update(hwzt)
begin

update jydxx
set jydzt= case when i.hwzt = '01' then '01'
when i.hwzt = '02' then '02'
when i.hwzt = '03' then '03'
end
from jydxx br,Inserted i
where br.jydbh = i.jydbh

end


读书人网 >SQL Server

热点推荐