Link to home
Start Free TrialLog in
Avatar of sniger
sniger

asked on

analyzing SQL statement, parsing in Java

I have an SQL statement :

SELECT ... WHERE YEAR = XXXX and MONTH = YY or YEAR = YYYY and MONTH < ZZ

I need to create set of all months with year  which will be included , for example
for  WHERE YEAR = 2012 and MONTH = 04 or YEAR = 2013 and MONTH > 5

it will be  (04/2012, 06/2013, 07/2013, ...) , the upper limit will be the current year and month

or
WHERE YEAR = 2012 and MONTH < 03 or YEAR = 2013 and MONTH > 5

it will be  (01/2008,.......02/2012, 06/2013,....)  the lower limit will be 01/2008

Any suggestions
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

This is confusing ;) Can you please omit the sql and just say in normal human terms what you're trying to achieve
This is tricky. You can try as given below.


Ex.1. YEAR = 2012 and MONTH = 04 or YEAR = 2013 and MONTH > 5

WHERE TO_DATE(YEAR||MONTH||'01', 'yyyymmdd') = TO_DATE('2012'||'04'||'01', 'yyyymmdd') or TO_DATE(YEAR||MONTH||'01', 'yyyymmdd') > TO_DATE('2013'||'05'||'01', 'yyyymmdd')


Ex.2. YEAR = 2012 and MONTH < 03 or YEAR = 2013 and MONTH > 5

WHERE TO_DATE(YEAR||MONTH||'01', 'yyyymmdd') < TO_DATE('2012'||'03'||'01', 'yyyymmdd') or TO_DATE(YEAR||MONTH||'01', 'yyyymmdd') > TO_DATE('2013'||'05'||'01', 'yyyymmdd')
As I understand it, sniger wants to write a piece of Java code that takes an arbitrary SQL SELECT statement that includes some WHERE clauses on the YEAR and MONTH columns and turns it into a list of months and years that could be returned by the statement.

I'm wondering where this requirement came from.
Which rdbms are you using?
ASKER CERTIFIED SOLUTION
Avatar of sniger
sniger

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sniger
sniger

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for sniger's comment #a39906606
Assisted answer: 166 points for amit_n_panchal's comment #a39900105
Assisted answer: 167 points for CPColin's comment #a39900939
Assisted answer: 167 points for CEHJ's comment #a39900958

for the following reason:

it solved my problem
My comment does not deserve points, as it offers no solutions.

sniger,

It sounds like you solved the problem yourself, without any of the comments in this question contributing to the solution. In this case, it's preferable for you to post your solution, then accept your own comment, without awarding points to any comment that did not actually contribute. If you do not want to post your solution, it's preferable that you request that this question be deleted instead.
Agree with you, CPColin.
I've requested that this question be closed as follows:

Accepted answer: 0 points for sniger's comment #a39906939

for the following reason:

Starting closing process on behalf of Asker.

Netminder
Senior Admin