日期:2014-05-17 浏览次数:20536 次
--drop table mocta
create table purtb
(请购单号 varchar(10),参考单号 varchar(10),备注 varchar(50))
create table mocta
(工单单号 varchar(10),订单单号 varchar(10))
insert into purtb
select '101','201','301' union all
select '102','302','302' union all
select '103','备料','备料'
insert into mocta
select '201','301' union all
select '202','302'
go
--drop trigger trigger_purtb_insert
create trigger dbo.trigger_purtb_insert
on purtb
for insert
as
update purtb
set 备注 = isnull((select t1.订单单号
from mocta t1
where i.参考单号 = t1.工单单号),
i.参考单号)
from inserted i
where purtb.请购单号 = i.请购单号 and
purtb.参考单号 = i.参考单号
go
insert into purtb(请购单号,参考单号)
select '104','201'
union all select '105','xxx'
--查询
select *
from purtb
/*
请购单号 参考单号 备注
101 201 301
102 302 301
103 备料 备料
104 201 301
105 xxx xxx
*/