我正在努力避免硬编码支付截止日期。财政年度是10/1到9/30。
如果某人在7月1日和12月31日之间加入,那么支付截止日期是下一个日历年,例如,2013年11月,某人已经支付并获得了2014年9月30日的支付截止日期。我需要2013年和2014年的工资
如果有人在1月1日和6月30日之间加入,那么付费通过日期是当前日历年度,例如,今年1月将是2014,并且他们的付费通过日期是2014年9月30日,我不再需要2013年付费通过组。
这是我所拥有的:如果getdate月份在1到6之间,那么我需要拉动9/30/ +本年度的付费用户。如果getdate月份在7和12之间,那么我需要选择拉动9/30当前年9/30 +下一年9/30的人。
select id, paid_thru, getdate()as today
from name
where datepart(mm,getdate())between 1 and 6 and datepart (yyyy,paid_thru)+1 = datepart(yyyy,getdate())
or
datepart(mm,getdate()) between 7 and 12 and datepart (yyyy,paid_thru) = datepart(yyyy,getdate())此查询仅提供2013年9月30日,因为该月是11月11日,因此我需要2013年9月30日和2014年9月30日的支付截止日期。
谢谢
发布于 2013-11-13 05:27:05
or子句需要用括号括起来。
select id,
paid_thru,
getdate() as today
from name
where
(
datepart( mm,getdate() ) between 1 and 6
and datepart(yyyy,paid_thru) + 1 = datepart(yyyy,getdate())
)
or
(
datepart(mm,getdate()) between 7 and 12
and datepart (yyyy,paid_thru) = datepart(yyyy,getdate())
)因为你没有任何括号,所以它满足了你的第一个或子句的一部分,即使另一部分没有通过。
https://stackoverflow.com/questions/19939600
复制相似问题