我当前正在尝试编写一个存储过程,该过程将显示所选的产品类型并计算所述产品的数量减去已租出但没有退货日期以显示多少的产品数量上述产品中的一部分目前可供出租。
到目前为止,仅尝试了“为空,为空,不为空”。我的一部分也认为我的COUNT个变量有误。
——-
ALTER PROCEDURE AvailableProducts(@ItemType VARCHAR(50)= NULL)
AS
BEGIN
DECLARE @AvailableCount INT
IF @ItemType IS NOT NULL
BEGIN
SELECT @AvailableCount=COUNT(SerialNumber.ProductID)-COUNT(Rental.SerialNumber)
FROM PRODUCT
INNER JOIN SerialNumber
ON Product.ProdID=SerialNumber.ProductID
INNER JOIN Rental
ON SerialNumber.SerialNumber=Rental.SerialNumber
WHERE ProdDescription=@ItemType AND @AvailableCount>0
SELECT COUNT(*) AS 'Number Available', RENTAL.StoreID,ProdDescription, ProdName,ProdSize, ProdFlex, ProdTerrain, ProdAbilityLevel,ProdShape,ProdRocker
FROM PRODUCT
INNER JOIN SerialNumber
ON Product.ProdID=SerialNumber.ProductID
INNER JOIN Rental
ON SerialNumber.SerialNumber=Rental.SerialNumber
WHERE ProdDescription=@ItemType
GROUP BY RENTAL.StoreID, ProdDescription, ProdName,ProdSize, ProdFlex, ProdTerrain, ProdAbilityLevel,ProdShape,ProdRocker
ORDER BY 2,1
RETURN (0);
END
ELSE
BEGIN
PRINT 'Please Enter one of the following Products:
"Snowboard"
"Skies"
"Splitboard"
"Boots"
"Goggles"
"Helmet"
to Show Products that are available to rent.'
RETURN (1);
END
END;
;