概述
下面是我用到的触发器,记录一下,有什么不懂得欢迎留言~
ALTER trigger [dbo].[tr_insertInformaftion] on [dbo].[SCM_Order_M]
for insert
as
--定义变量
declare @T2_OrderCode varchar(20),
@PtClassify nvarchar(10),
@OrderName nvarchar(50),
@ProBrand nvarchar(25)
set @T2_OrderCode=(select OrderCode from inserted) --获取订单编号,赋值
set @PtClassify=(select PtClassify from inserted )--获取下单类型,来判断推送人员
set @OrderName=(select OrderName from inserted)--判断是否是退单或者外采
set @ProBrand=(select top 1 (ProBrand) from JZDATA..SCM_Order_T2 where OrderCode=@T2_OrderCode)
if @PtClassify='主材' and @OrderName not like'%退订%'and @OrderName not like'%外采%'
begin
--insert into Questionnaire..[Product_Text]([str1],[str2],[str3])values('33','44','55')
insert into Questionnaire..Product_LS(DriverPost, DriverName, DriverAccount,
SupplierName, SupplierProductDL, SupplierProductName, ProjectName,
ProjectCode, SendState, IsSend, RelevanceChart, OldTime)
select PostName,MemberName,MemberAccount,SupplierName,BroadHeading,@ProBrand,CusName+'-'+ProjectAddress,CusCode,
'0','0','1',createTime
from(
select distinct @ProBrand ProBrand,Position,SupplierName,BroadHeading,CusName,a.CusCode,ProjectAddress,createTime
,b.MemberAccount,b.MemberName,b.PostName
from (
select AddDuty Position,Supplier SupplierName,PtName BroadHeading,CusName,CusCode,ProjectAddress,CreateTime createTime
from JZDATA..SCM_Order_M where OrderCode=@T2_OrderCode)a
left join(
select * from JZDATA..CRM_ProjectTeamMember
where PostName='客户经理' or PostName='主创设计师' or PostName='主材专员'
)b
on a.CusCode=b.CusCode
where Position<>'供应商'
and MemberAccount not like '%HGH%'
and MemberAccount not like '%NGB%'
and MemberAccount is not null
)c
end
if @PtClassify='配饰' and @OrderName not like'%退订%'and @OrderName not like'%外采%'
begin
insert into Questionnaire..Product_LS(DriverPost, DriverName, DriverAccount,
SupplierName, SupplierProductDL, SupplierProductName, ProjectName,
ProjectCode, SendState, IsSend, RelevanceChart, OldTime)
select PostName,MemberName,MemberAccount,SupplierName,BroadHeading,@ProBrand,CusName+'-'+ProjectAddress,CusCode,
'0','0','1',createTime
from(
select distinct @ProBrand ProBrand,Position,SupplierName,BroadHeading,CusName,a.CusCode,ProjectAddress,createTime
,b.MemberAccount,b.MemberName,b.PostName
from (
select AddDuty Position,Supplier SupplierName,PtName BroadHeading,CusName,CusCode,ProjectAddress,CreateTime createTime
from JZDATA..SCM_Order_M where OrderCode=@T2_OrderCode)a
left join(
select * from JZDATA..CRM_ProjectTeamMember
where PostName='客户经理' or PostName='主创设计师' or PostName='配饰设计师'
)b
on a.CusCode=b.CusCode
where Position<>'供应商'
and MemberAccount not like '%HGH%'
and MemberAccount not like '%NGB%')c
end
最后
以上就是帅气往事为你收集整理的记录一下触发器的写法的全部内容,希望文章能够帮你解决记录一下触发器的写法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复