Skip to main content
Participating Frequently
August 22, 2012
Question

How could this query be coded?

  • August 22, 2012
  • 1 reply
  • 720 views

I'm racking my brain trying to figure this one out...this is an old query of mine being retooled...

DB has a field for MONTH and a field for YEAR...as well as HOURS for each record.

This query is pulling a sum of hours for a date range, that will be a year from Oct to Sep.

So I want a query that says:

Select * from October to December of Last Year, AND all months from January of the current year up to a "selected" month.

I have setup for current year, prior year, and selected month (from a dropdown list).

I've already tried something like:

SELECT SUM(hours) AS Total FROM TABLENAME

WHERE service_year = #session.prior_year# AND service_month >= 10 AND service_month <=12 AND service_year = #session.selected_year# AND service_month >= 1 AND service_month <= #session.selected_month#

No dice of course, logically that doesn't work anyway after looking at it.

Any ideas?  I've tried various forms of evaluation levels of operators, no dice.

Thanks in advance!

This topic has been closed for replies.

1 reply

Legend
August 22, 2012

Maybe:

WHERE

(service_year = #session.prior_year# AND service_month >= 10)

OR (service_year = #session.selected_year# AND service_month <= #session.selected_month#)

Participating Frequently
August 22, 2012

Perfect Steve that's exactly what I need thank you!!

It was a syntax issue more than of a logic issue.

Thanks again!