December 7, 2007 at 2:26 pm
Ok, I'm not sure how to include something in a where clause....probably easy to do and I'm not looking in the right places or something. So here is my statement that I'm want
@Inst_ID int,
@status char(1)
SELECT
Inventory.Car,
Inventory.StockNumber,
SUM(InventoryService.FinalCost) As TotalCost
FROM Inventory
LEFT JOIN InventoryService ON Inventory.Inventory_ID = InventoryService.Inventory_ID
WHERE
Inventory.Inst_ID = @Inst_ID AND
Inventory.Status LIKE @status AND
SUM(InventoryService.FinalCost) > 0.00 --this part is wrong of course
So, my sum statement doesn't work in my WHERE clause, how do I make it work?
December 7, 2007 at 2:37 pm
Ok I think I figured out what I need...
@Inst_ID int,
@status char(1)
SELECT
Inventory.Car,
Inventory.StockNumber,
SUM(InventoryService.FinalCost) As TotalCost
FROM Inventory
LEFT JOIN InventoryService ON Inventory.Inventory_ID = InventoryService.Inventory_ID
WHERE
Inventory.Inst_ID = @Inst_ID AND
Inventory.Status LIKE @status
GROUP BY Inventory.Car, Inventory.StockNumber
HAVING SUM(InventoryService.Finalcost) > 0.00
December 10, 2007 at 12:26 pm
Sometimes it just comes to you. ANy aggreagate function that needs to be in the GROUP BY will need to have it's criteria in the HAVING clause.:hehe:
Kindest Regards,
David
** Obstacles are those frightening things that appear when we take our eyes off the goal. **
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply