Solved

analyzing SQL statement, parsing in Java

Posted on 2014-02-27
11
287 Views
Last Modified: 2014-03-17
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
0
Comment
Question by:sniger
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39893152
This is confusing ;) Can you please omit the sql and just say in normal human terms what you're trying to achieve
0
 
LVL 21

Expert Comment

by:Amitkumar Panchal
ID: 39900105
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')
0
 
LVL 14

Expert Comment

by:CPColin
ID: 39900939
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39900958
Which rdbms are you using?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Accepted Solution

by:
sniger earned 0 total points
ID: 39906606
ok, I got around the problem, by creating a dummy record and running SQL on it, to create my columns
0
 

Author Comment

by:sniger
ID: 39906939
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
0
 
LVL 14

Expert Comment

by:CPColin
ID: 39906940
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.
0
 
LVL 21

Expert Comment

by:Amitkumar Panchal
ID: 39907046
Agree with you, CPColin.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 39918559
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now