Link to home
Start Free TrialLog in
Avatar of clintnash
clintnashFlag for United States of America

asked on

Query that needs a conditional where clause (Where applies for one column but not another)

I have a query that produces a simple result set based on date.  This is used as the datasource for a report.  The users added th option to day that they want year to date totals as well.  So its count(c.checkinID) as YTD, however with a a where clause that accepts todays date I am not sure how to approach this.

select l.lunch, count(c.checkinID) as Total_today
from camps_checkin c, camps_lunch l
where c.lunchID > 0 and
c.lunchId = l.lunchID and
c.dateused = @dateused
Group by c.lunchID, l.lunch
order by count(c.checkinID) DESC;

Now the results look like

Lunch              Totay_Today
---------------------------------------
Pizza                      342
Hot Dog                  197

What I need would look like this.

Lunch              Totay_Today                 YTD
--------------------------------------------------------
Pizza                      342                        24,764
Hot Dog                  197                        18,965

Any advise will be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of David Todd
David Todd
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clintnash

ASKER

That nailed it. thank you...