Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with date selction based on Month and Year 1

Status
Not open for further replies.

vega83

Programmer
Jun 12, 2008
141
US
Friends, I need help on below selection critieria in DB2.
Below where clause works fine, but only If I pass my paramter in DATE or DATE TIME format. I wan to give my end user an option to select by Month Year format May2009 instead of 05/23/2009 or so.

Below selection criteria gives me data for last 12 months.

WHERE DATE(ADDED_DT) >= ((DATE({?Report_Date}) - Day(DATE({?Report_Date})) day)+1 day) - 12 month
AND DATE(ADDED_DT) <= (((DATE({?Report_Date}) - Day(DATE({?Report_Date})) day)+1 day) + 1 month) - 1 day

ANy help on how to get that?
Thanks a ton,
V
 



Hi,

A date is not a month or a month and year. It is year, month and day.

If you have a month and year, you must use those values to product a date; presumably either the FIRST or LAST day of the given month and year.

Alternatively, convert the date value to month and year to compare with your values.

Keep in mind that the format May2009 will produce incorrect results for use in cirteria, as Apr2009 colates BEFORE Jan2009. Rather, use a yyyymmm format.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Code:
Year(Date)*100+Month(date)


Code:
cast(Year(Date)*100+Month(date) as varchar(6))





Ties Blom

 
Blom Many thanks, one final question how to we again break this paramter in where condtion.
Year(Date)*100+Month(date) has worked, but getting error for
cast(Year(Date)*100+Month(date) as varchar(6))

Below is where condtion where I want to break
Year(Date)*100+Month(date) accordingly

WHERE DATE(ADDED_DT) >= ((DATE({?Report_Date}) - Day(DATE({?Report_Date})) day)+1 day) - 12 month
AND DATE(ADDED_DT) <= (((DATE({?Report_Date}) - Day(DATE({?Report_Date})) day)+1 day) + 1 month) - 1 day

 
How about:

Code:
Year(Added_DT)*100+Month(Added_DT)
>= Year({?Report_Date})*100-100+Month({?Report_Date})
and
Year(Added_DT)*100+Month(Added_DT)
<= Year({?Report_Date})*100-100+Month({?Report_Date})




Ties Blom

 
My example should read:

Code:
Year(Added_DT)*100+Month(Added_DT)
>= Year({?Report_Date})*100-100+Month({?Report_Date})
and
Year(Added_DT)*100+Month(Added_DT)
<= Year({?Report_Date})*100+Month({?Report_Date})

Success!

Ties Blom

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top