Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

analyzing SQL statement, parsing in Java

Posted on 2014-02-27
11
Medium Priority
?
295 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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