Solved

analyzing SQL statement, parsing in Java

Posted on 2014-02-27
11
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 39900958
Which rdbms are you using?
0
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
Java: anonymous class 4 54
restrict decimal places for double datatype 10 49
Netbeans and org.apache.commons.lang3 issue 3 53
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 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