Chapter Eleven – The Web Server Environment
G. Write a stored procedure that receives values for ItemID and NewPriceUSD and sets the
value of PriceUSD to NewPriceUSD for the row having the given value of ItemID.
Generate an error message if no row has the given value of ItemID. Using your sample
database, demonstrate that your stored procedure works.
Here is the code for the stored procedure Update_PriceUSD:
CREATE OR ALTER PROCEDURE [dbo].[Update_PriceUSD]
@PurchaseItemID Int,
/* Check to see if a Purchase with the PurchaseItemID is in the database */
SELECT @rowCount = COUNT(*)
FROM dbo.PURCHASE_ITEM
WHERE dbo.PURCHASE_ITEM.PurchaseItemID = @PurchaseItemID;
IF @rowCount = 0
BEGIN
PRINT ‘======================================================================’
PRINT ”
PRINT ‘ There is no PURCHASE_ITEM with PurchaseItemID: ‘ +
CONVERT(Char(12),@PurchaseItemID)
PRINT ‘======================================================================’
PRINT ”
PRINT ‘ The PriceUSD for the PURCHASE_ITEM with PurchaseItemID: ‘ +
CONVERT(Char(12),@PurchaseItemID)
PRINT ”
PRINT ‘ has been updated from: ‘ + CONVERT(Char(12),@priorPriceUSD)
PRINT ”