Solved

analyzing SQL statement, parsing in Java

Posted on 2014-02-27
11
285 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 20

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 20

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Increment alphanumeric sequence 6 81
Math Question 1 55
backtracking recursion  code 19 41
Java - Why doesn't this JFrame work 3 18
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

10 Experts available now in Live!

Get 1:1 Help Now