... HAVING sum(c.actualqty) < @UserLimit>In the query below I am returning all rows of supply items used for a given date range. My ultimate goal is to limit the query to return only rows where the TotalUsed column calculate to less than some number passed by the user. I don't know how to do that part of it.
>declare @tiDept as int >declare @DateFrom as datetime >declare @DateTo as DateTime >declare @tiMinUsage as int > >set @tiDept = 1 >set @dateFrom = '10/01/2001 00:00' >set @dateTo = '10/01/2002 23:59' > > >SELECT i.primedesc, i.catalogno, sum(c.actualqty) as TotalUsed, > (Select isnull(dbo.coinv.medication,0) from dbo.coinv where invid=i.invid) as Medication > FROM dbo.cocasedata c INNER JOIN > dbo.coinv i ON c.linkedid = i.invid INNER JOIN > dbo.meetings ON c.meetingnumber = dbo.meetings.meetingnumber >WHERE (dbo.meetings.iscompleted = 1) >AND dbo.meetings.begintime between @dateFrom and @dateTo >group by invid,primedesc,catalogno >