我试图找出一个查询来说明今天什么时候属于这个财政年度(1/11 - 31/10),运行这组案例语句,但是当今天是下一个财政年度时运行下一组等等。 .
我试过嵌套 CASE 语句但没有工作。下面只是解释我想要做什么..
感谢您的关注!
IF Getdate() Between '2012-11-01 00:00' AND '2013-10-31 23:59' -- is it this year?
THEN
CASE
WHEN B.saledate Between '2011-11-01 00:00' AND Getdate()-365 THEN 'Yes'
WHEN B.saledate Between '2012-11-01 00:00' AND Getdate() THEN 'Yes'
Else 'No'
AS 'Financial year to date',
END
IF Getdate() Between '2013-11-01 00:00' AND '2014-10-31 23:59' -- is it this year yet?
THEN
CASE
WHEN B.Created Between '2011-11-01 00:00' AND Getdate()-730 THEN 'Yes'
WHEN B.Created Between '2012-11-01 00:00' AND Getdate()-365 THEN 'Yes'
WHEN B.Created Between '2013-11-01 00:00' AND Getdate() THEN 'Yes'
Else 'No'
AS 'Financial year to date',
END
END