Avatar of clintnash
clintnash
Flag 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.
Microsoft SQL Server

Avatar of undefined
Last Comment
clintnash

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Todd

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
clintnash

ASKER
That nailed it. thank you...
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck