Sybase 保留5个business day和4个month end

需求变化:保存7天内的数据,和最近4个月末的数据 -->保留最近5个business day和4各与月末的数据

第一个需求sybase代码的编写:(其中runcob是一个字段)

s.RunCob < dateadd(dd, -7, convert(char(8),'20091027',112)) 
and s.RunCob != dateadd(day,-1,convert(datetime,'01/' + convert(char(2),DatePart(mm, DateAdd(mm, -1, '20091027'))) +'/'+datename(year,'20091027'),103))
and s.RunCob != dateadd(day,-1,convert(datetime,'01/' + convert(char(2),DatePart(mm, DateAdd(mm, -2, '20091027'))) +'/'+datename(year,'20091027'),103))
and s.RunCob != dateadd(day,-1,convert(datetime,'01/' + convert(char(2),DatePart(mm, DateAdd(mm, -3, '20091027'))) +'/'+datename(year,'20091027'),103))
and s.RunCob != dateadd(day,-1,convert(datetime,'01/' + convert(char(2),DatePart(mm, DateAdd(mm, -4, '20091027'))) +'/'+datename(year,'20091027'),103))



第二个需求:(其中$前缀地为perl的变量)
select distinct top 5 Cob,ServiceType,'D' as KeepIndicator into #tmp1 from 表A where Frequency = 'D' and ServiceType = 'EPE' order by Cob desc
insert into #tmp1 select distinct top 4 Cob,ServiceType,'M' as KeepIndicator from 表A where Frequency = 'M' and ServiceType = 'EPE' order by Cob desc
select distinct Cob,Frequency,ServiceType,'D' as KeepIndicator into #tmp2 from 表A where Frequency = 'D' and ServiceType = 'PSE' order by Cob desc
update #tmp2 set KeepIndicator = 'M' where datediff(mm,Cob,dateadd(dd,(CASE datename(dw,Cob) WHEN 'Friday' THEN 3 ELSE 1 end),Cob))>0 and ServiceType = 'PSE'
insert into #tmp1 select distinct top 5 Cob,ServiceType,Frequency,KeepIndicator from #tmp2 where KeepIndicator = 'D' and ServiceType = 'PSE' order by Cob desc
insert into #tmp1 select distinct top 4 Cob,ServiceType,Frequency,KeepIndicator from #tmp2 where KeepIndicator = 'M' and ServiceType = 'PSE' order by Cob desc
select distinct top 5 Cob,ServiceType,Frequency,KeepIndicator into #tmp1 from #tmp3 where KeepIndicator = 'D' and ServiceType = 'PSE' order by Cob desc
delete from $tblNameBadTranError where BatchId not in (select BatchId from #tmp1)
delete from $tblNameBadTranTrans where BatchId not in (select BatchId from #tmp1)
delete from $tblNameBadTranSummary where BatchId not in (select BatchId from #tmp1)
delete from $tblNameBadTranErrorSum where BatchId not in (select BatchId from #tmp1)
delete from $tblNameBadTranSess where BatchId not in (select BatchId from #tmp1)
delete from PseBadLKUPCob where convert(varchar(8),Cob,112)+Frequency+ServiceType not in (select BatchId from #tmp1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值