Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with Query
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Help with Query
Miscellaneous
Thread ID:
00706345
Message ID:
00706345
Views:
50
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
Next
Reply
Map
View

Click here to load this message in the networking platform