MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query to pull data between two fiscal periods

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
SMS
Beginner


Joined: 16 Oct 2005
Posts: 53
Topics: 24

PostPosted: Mon Dec 03, 2007 5:50 pm    Post subject: Query to pull data between two fiscal periods Reply with quote

Hi,

Please help in correcting the below query.
The below query is to pull the data between two fiscal months of same or different year.
Code:

SELECT
           A,
           b,
           ,fiscal_year
           ,fiscal_month
           ,SUM(z)

         FROM TABLE1
         WHERE  ( fiscal_year  = 2007  AND fiscal_month >= 11)
                 AND ( fiscal_year = 2008  AND fiscal_month  <= 1)
             GROUP BY A, B,fiscal_year, fiscal_month
             ORDER BY A, B, fiscal_year, fiscal_month
             WITH UR


In Table1, Fiscal year and fisc month will be like this

Code:

Fiscal Year    Fiscal month

2007             9
2007             10
2007             11
2007             12

2008             1
2008             2
2008             3
2008             4
2008             5
2008             6


Now I need to pull data between 2007,11 and 2008,1 (Fisc yr , Fisc month).

Sometimes I need to pull data from the same year. For that below condition works correctly.

(Fiscal month between x and y
AND Fiscal year BETWEEN x and y)


I appreciate any suggestions on this.

Thanks,
SMS
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Dec 03, 2007 7:08 pm    Post subject: Reply with quote

SMS,

Try this untested sql

Code:

SELECT A
      ,B
      ,fiscal_year
      ,fiscal_month
      ,SUM(z)
  FROM TABLE
 WHERE (fiscal_year,fiscal_month) BETWEEN 200711 AND 200801
 GROUP BY A
         ,B
         ,fiscal_year
         ,fiscal_month
  WITH UR
  ;


Hope this helps...

Cheers
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
advoss
Beginner


Joined: 23 Aug 2005
Posts: 26
Topics: 0

PostPosted: Tue Dec 04, 2007 10:23 am    Post subject: Reply with quote

Are fiscal year and fiscal month numeric or character? I like Kolusu's idea, but I think if they are character, you would need a leading zero on the fiscal months that are less than 10, and then you would need to concatenate the two columns. If they are number, you could combine them with simple math of 100*fiscal_year+fiscal month.
_________________
Alan Voss
Back to top
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Tue Dec 04, 2007 10:48 am    Post subject: Re: Query to pull data between two fiscal periods Reply with quote

SMS wrote:
Hi,

Please help in correcting the below query.
The below query is to pull the data between two fiscal months of same or different year.
Code:

SELECT
           A,
           b,
           ,fiscal_year
           ,fiscal_month
           ,SUM(z)

         FROM TABLE1
         WHERE  ( fiscal_year  = 2007  AND fiscal_month >= 11)
                 AND ( fiscal_year = 2008  AND fiscal_month  <= 1)
             GROUP BY A, B,fiscal_year, fiscal_month
             ORDER BY A, B, fiscal_year, fiscal_month
             WITH UR


In Table1, Fiscal year and fisc month will be like this

Code:

Fiscal Year    Fiscal month

2007             9
2007             10
2007             11
2007             12

2008             1
2008             2
2008             3
2008             4
2008             5
2008             6


Now I need to pull data between 2007,11 and 2008,1 (Fisc yr , Fisc month).

Sometimes I need to pull data from the same year. For that below condition works correctly.

(Fiscal month between x and y
AND Fiscal year BETWEEN x and y)


I appreciate any suggestions on this.

Thanks,
SMS


I don't see anything wrong with what you have for the first query but for the second you don't need a between for the fiscal_year just a equal with a between for the fiscal_month (if you want less than a full year).
Back to top
View user's profile Send private message
SMS
Beginner


Joined: 16 Oct 2005
Posts: 53
Topics: 24

PostPosted: Tue Dec 04, 2007 1:02 pm    Post subject: Reply with quote

Kolusu,

Your suggestion worked. Before posting, I tried with MMYYYY but never thought of YYYYMM. Smile

Advoss,

As you mentioned, I had to manipulate the data type.

Craig,

I tried my old query, but it was not working.


Thanks to all of you guys.

Regards,
SMS
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group