2013-09-04 2 views
0

오늘이 회계 연도 (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 
+0

각 행의 회계 연도를 얻는 방법에 대한 해결책을 추가했습니다. 당신이 그것을하고 싶은 wht를 설명하면, 나는 더 많은 정보를 제공 할 수 있습니다. –

답변

0

감사합니다. 도움을 주셔서 감사합니다.하지만이 회계 연도의 핵심은 회계 연도뿐 아니라 올해도 마찬가지입니다.

아래와 같이 해결됩니다. 그것은 매년 새로운 블록을 추가하는 것을 의미합니다. 그러나 그것이 지금 제가있는 곳입니다.

CASE 
     WHEN 
     Getdate() Between '2012-11-01 00:00' AND '2013-10-31 23:59' AND 
     (
     cast(convert(char(11), B.Created, 10) as datetime) Between '2009-11-01 00:00' AND (cast(getdate()-1096 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2010-11-01 00:00' AND (cast(getdate()-731 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2011-11-01 00:00' AND (cast(getdate()-366 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2012-11-01 00:00' AND (cast(getdate() as date)) 
     ) 
     THEN 'Yes' 

     WHEN Getdate() Between '2013-11-01 00:00' AND '2014-10-31 23:59' AND 
     (
     cast(convert(char(11), B.Created, 10) as datetime) Between '2009-11-01 00:00' AND (cast(getdate()-1461 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2010-11-01 00:00' AND (cast(getdate()-1096 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2011-11-01 00:00' AND (cast(getdate()-731 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2012-11-01 00:00' AND (cast(getdate()-366 as date)) OR 
     cast(convert(char(11), B.Created, 10) as datetime) Between '2013-11-01 00:00' AND (cast(getdate() as date)) 
     ) 
     THEN 'Yes' 

Else 'No' 
END 
AS 'Financial year to date', 
0

이렇게하면 코드가 계속 증가 할 것입니다.

특정 회계 연도 오유가 그것을 시도 할 수 얻으려면 : 그래서

DECLARE @DateToCheck AS DATETIME 

SET @DateToCheck = '20130101' 

SELECT YEAR(DATEADD(mm,-10,@DateToCheck)) 

당신이 TransactionDate

SELECT YEAR(DATEADD(mm,-10,TransactionDate)) 
FROM Transactions 

당신에게 각 거래의 회계 연도를 얻을 것이다 날짜 시간 필드와 테이블 Transactions이있는 경우 .