All Forums Database
umaprabu 1 post Joined 09/14
16 Sep 2014
SQL

I have a table AAA  which has 3 columns as Month_No,Year_No and Profit.
I want to select next 15 months profit data along with month and year from table AAA.
Can anyone help me to form the teradata Query for this?
Example:
Table Name:AAA
Month_No      Year_No    Profit
2                     2011       10
3                     2014       20
5                     2015       20
11                   2014       30
12                   2013       40
7                     2015       40
9                     2014       50
 
If current date is 16/Sep/2014 then i need to select data from sep/2014 to Nov/2015 in AAA table
If Current date is 1/Dec/2013 then I need to select data from dec/2013 to feb/2015 in AAA table.
 
 
 

dnoeth 4628 posts Joined 11/04
16 Sep 2014

You might simply utilize Teradata's sys_calendar (or yor own calendar implementation):

WHERE (Year_No, Month_No)
   IN (SELECT year_of_calendar, month_of_year
       FROM sys_calendar.calendar
       WHERE calendar_date BETWEEN CURRENT_DATE
                           AND ADD_MONTHS(CURRENT_DATE,14))

 

Dieter

You must sign in to leave a comment.