You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
D6JIEFENGMAIL/doc/sql/p_gen_sea_Origi_warntask.sql

81 lines
3.1 KiB
Transact-SQL

/****** Object: StoredProcedure [dbo].[p_gen_sea_Origi_warntask] Script Date: 12/13/2017 17:33:59 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[p_gen_sea_Origi_warntask]
@tskCount int output
AS
begin
---清理临时表
---------必须是两个..
if object_id('tempdb..#tempWarnlist') is not null Begin
drop table #tempWarnlist
END
---创建临时表
CREATE TABLE [dbo].#tempWarnlist(
[ID] [int] IDENTITY(1,1) NOT NULL,
[MblNo] [varchar](20) NOT NULL,
[WarnDate] [datetime] NOT NULL,
[WarnType] [varchar](20) NOT NULL,
[createdate] [datetime] NOT NULL default getdate()
)
---将相关数据插入到临时表
insert into #tempWarnlist (mblno,warndate,warntype)
select tdh, ,'预警提醒'
from
(
select
ltrim(
rtrim(SUBSTRING(
substring( ,charindex('number',v.,1)+6,LEN(v.)-charindex('number',v.,1)),1
,LEN(substring( ,charindex('number',v.,1)+6,LEN(v.)-charindex('number',v.,1)))-
LEN(' is now available'))
)
) as tdh, cast( as DATETIME) as ,
from
(select m.id,m.,m.,m.,DATEDIFF(mi,m.,m.)as minYsh
from t_op_seae_edi_mail m where like '%origin%'and >=cast(GETDATE()-3 as DATE)and <cast(GETDATE()+1 as DATE)
and m. < DATEADD(MI,-30,GETDATE())
)v
)
vv
where tdh not in
(
select t. -- , t.任务类型
from t_op_task t where t.>=cast(GETDATE()-3 as DATE)and < DATEADD(MI,-30,GETDATE())
and t.='ORIGINAL'
)
and not exists ( select Mblno from t_op_seae_task_warn_mblno w where w.MblNo= vv.tdh and w.Warndate=vv.)
---将临时表的数据插入到预警任务列表
set @tskCount=( select COUNT('MblNo') from #tempWarnlist);
----------------
insert into t_op_seae_task_warn_mblno (mblno,warndate,warntype)
select [MblNo], [WarnDate] , [WarnType]
from #tempWarnlist
----形成任务(注意这里有问题)
insert into t_op_task
([任务编号] , [任务类型],[任务来源],[任务状态],[任务说明]
,[发起人] ,[录入日期] ,[任务开始时间] ,[完成方式]
,[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号])
select [任务编号] , [任务类型],[任务来源],[任务状态],[任务说明]
,[发起人] ,[录入日期] ,[任务开始时间] ,[完成方式]
,[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号] from
(
select NEWID() as ,wn.WarnType as [任务类型] ,'邮件分析' as ,'待确认' as ,'有Original Bill邮件无正本' as ,
'DEMO-SA' as ,GETDATE() as ,wn.WarnDate as [任务开始时间],'手动' as ,
wn.MblNo as ,null as ,null as ,null as ,case when LEN(isnull(s.,''))<1 then 1 else 0 end as ,s. as ,s. as SEA
,s.
from #tempWarnlist wn left join t_op_seae s on wn.MblNo= s. and s.='普通货' )
v where v. is null or v.='整箱'
return @tskCount
end;