-- 正本pdf 与邮件中的征文进行比较,看pdf 文件是否缺失 select * from t_op_seae s where s.主提单号 in ( 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, 邮件发送日期, 邮件主题 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()-3 as DATE)and 任务开始时间< DATEADD(MI,-10,GETDATE()) and t.任务类型='ORIGINAL' ) ) ---------------- ---清理临时表 ---------必须是两个.. 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()-7 as DATE)and 邮件发送日期=cast(GETDATE()-7 as DATE)and 任务开始时间< DATEADD(MI,-10,GETDATE()) and t.录入日期< DATEADD(MI,-50,GETDATE()) and t.任务类型='ORIGINAL' and t.任务来源='FTP' ) and not exists ( select Mblno from t_op_seae_task_warn_mblno w where w.MblNo= vv.tdh and w.Warndate=vv.邮件发送日期) ---将临时表的数据插入到预警任务列表 --- delete from t_op_seae_task_warn_mblno --- select * from t_op_seae_task_warn_mblno ---------------- insert into t_op_seae_task_warn_mblno (mblno,warndate,warntype) select [MblNo], [WarnDate] , [WarnType] from #tempWarnlist ----形成任务(注意这里有问题) insert into t_op_task ([任务编号] , [任务类型],[任务来源],[任务状态],[任务说明] ,[发起人] ,[录入日期] ,[任务开始时间] ,[完成方式] ,[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号]) select NEWID(),wn.WarnType ,'邮件分析','待确认','有Original Bill邮件无正本' , 'DEMO-SA',GETDATE(),wn.WarnDate,'手动', wn.MblNo,null,null,null,case when LEN(isnull(s.客服员,''))<1 then 1 else 0 end ,s.客服员,s.编号 from #tempWarnlist wn left join t_op_seae s on wn.MblNo= s.主提单号 and s.业务类型='普通货' ------------------------------ --delete from t_op_seae_task_warn_mblno; delete from t_op_task where 任务类型='预警提醒' select * from t_op_task where 任务类型='预警提醒' select * from t_op_seae s where s.主提单号 in ( select m.mblno from t_op_seae_task_warn_mblno m ) select distinct s.装运方式 from t_op_seae s select cast(GETDATE() as DATE),DATEADD(MI,-10,GETDATE()),GETDATE();