我需要你的帮助。我有这个代码来查询我的机器,这些机器在租赁,库存和我的网点上。但这只适用于我输入一个itemID。这意味着它一次只能查询一个项目。我需要查询租赁和网点上的机器数量,与现有库存数量平行。谢谢 !计数表上的项目
`alter procedure GetItemsForQueries
@itemID varchar(15)
as begin
select i.ItemName, m.MachineModel, i.SellingPrice, i.QuantityOnHand,
(select COUNT(*) from ClientMachine where AcquisitionType = 'Rental' and ItemID = @itemID) as 'Quantity on Rentals',
(select COUNT(*) from OutletMachine where ItemID = @itemID) as 'Quantity on Outlets'
from Item i inner join Machine m on (m.ItemID = i.ItemID)
where i.ItemID = @itemID
end`
只是增加了一些代码到你的答案,而这一次似乎是最近的我需要什么。谢谢 ! – 2013-05-10 17:28:02
谢谢!几乎每个人都做了同样的事情,这是一个非常常见的模式,在编写查询时你会反复使用。 – Stephen 2013-05-10 17:29:38