+ -
当前位置:首页 → 问答吧 → 求大虾们帮忙将这条语句简化掉..

求大虾们帮忙将这条语句简化掉..

时间:2011-08-24

来源:互联网

select 1 from RePlan where PlanFrequency =1 and ceiling ((datepart(day,getdate())-datePart(day,Startdate))%(IsNull(RDay,0)))=0 and (Startdate < GETDATE()) AND (GETDATE() < Enddate) AND (ClosePlan = 0) and (AutherID<>'')

union all

select 1 from RePlan where PlanFrequency=2 and charindex(convert(varchar(10),datepart(dw,getdate())),RWeek)>0 and (Startdate < GETDATE()) AND (GETDATE() < Enddate) AND (ClosePlan = 0) and (AutherID<>'')

union all 

select 1 from RePlan where PlanFrequency=3 and RMType=1 and ceiling((datepart(Month,getdate())-datePart(Month,Startdate))%(IsNull(RMonth,0)))=0 
and ceiling ((datepart(day,getdate())-datePart(day,Startdate))%(IsNull(RMonthDay,0)))=0 and (Startdate < GETDATE()) AND (GETDATE() < Enddate) AND (ClosePlan = 0) and (AutherID<>'') 

union all 

select 1 from RePlan where PlanFrequency=3 and RMType=2 and ceiling((datepart(Month,getdate())-datePart(Month,Startdate))%(IsNull(RMonthWeek,0)))=0 and
charindex(convert(varchar(10),datepart(dw,getdate())),RPerWeek)>0 and RPerDay=round((datepart(day,getdate()))/7,0,1)+1 and (Startdate < GETDATE()) AND (GETDATE() < Enddate) AND (ClosePlan = 0) and (AutherID<>'')

作者: cyf0719   发布时间: 2011-08-24

先帮你顶顶。。。。。。。。。。

作者: sgzhou12345   发布时间: 2011-08-24

你想实现什么功能呀???

作者: sgzhou12345   发布时间: 2011-08-24

按不同属性做不同的查询,然后再合并起来
好像没什么问题啊

作者: sz_haitao   发布时间: 2011-08-24

每一段分别试一下。

作者: shijies   发布时间: 2011-08-24

热门下载

更多