有3张表:
Suppl, fields: (Code_name, Tasknum, Pki_num, Group_eng, Name, Descr, Cost, Quan, shop)
Maker, fields : (Code_maker, Code_maker_arch, Code_name, provider)
Arrival, fields: (Code_arr, Code_maker, quan_arr)
我需要获取一个表(用于导出到 Excel),例如 update_501(Group_eng,Name,Descr,quan_arr),其中将包含 group_eng_501 的唯一“Descr”。字段“quan_arr”需要为每个唯一的“Descr”保留来自表 Arrival.quan_arr 的字段总和。
第一的:
Insert dbo.update_501(Group_eng, Name, Descr)
select Group_eng, Name, Descr
from Suppl
where (Group_eng = 501)
group by Group_eng, Name, Descr
then: 触发器,它为 update_501 添加一个唯一的“descr”
ALTER trigger [update_pki_501] ON [dbo].[Suppl]
After Insert
as
begin
Set nocount on;
if (not(exists(select * from [INSERTED])))
return;
Insert dbo.update_501(Group_eng, Name, Descr)
select I.Name
,I.Descr
,I.Group_eng
from Inserted I
where (I.Group_eng = 501)
and not exists(select * from dbo.update_501 x where x.Group_eng=I.Group_eng and x.Descr = I.Descr)
end
请帮助在来自 Arrival.quan_arr 的 update_501.quan_arr 中添加(和求和)触发器