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 allselect 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<>'')