cancel
Showing results for 
Search instead for 
Did you mean: 

Hello SCN need your help regarding Year and Month conflict in my data

0 Kudos

Hi all,

                I have data in a table with few days of previous year data and this year data and it was working fine until December 2014 but when the year changed to 2015 my report started showing zero values .After investigating I found that there is some data from Dec 2014 with last three days of the year .

The SQL script is something like this.

SELECT MAX(MONTH(SLS_DATE)), MAX(YEAR(SLS_DATE)) FROM "SCHEMA"."TABLE NAME";

This script worked fine when Month was increasing with same year but when year increased by one and month decreased from 12 to 01 this script failed to show current year data instead it was showing this.

Accepted Solutions (1)

Accepted Solutions (1)

lbreddemann
Active Contributor
0 Kudos

Seriously, I really don't understand how your table or your data looks like.

It's just not in your problem statement.

Anyhow, the SQL you posted selects two independent information:

The highest value for MONTH and the highest occurring YEAR in your table.

I *guess* (I have to, since you did not tell us, what you actually wanted to do) that you wanted the month and year component of the "highest" date value in your table.

If that's correct, the statement rather should be this:

SELECT month( max(SLS_DATE)) as max_date_month

          , year( max(SLS_DATE)) as max_date_year

FROM ...

- Lars

Answers (1)

Answers (1)

0 Kudos

Thanks Lars,

                    Though you didn't understood what's in my table ,your general guess was correct your Select statement worked for me.

Thanks,

Hari