As is, this code executes with no errors; however, it doesn't seem to be performing the calculation. I think this may be because the line SET @MajorID = MajorID is in the wrong place. Anytime I try to move it though, I get an error Msg 102, Level 15 State 1 Line 2. For the life of me, I can't figure out why line 2 would suddenly be a problem just because the SET was moved.
Code:
DROP TABLE BookPriceIncrease_ByMajor
SELECT Majors.MajorID, Majors.Description, Books.BookID,
Books.Title, Books.AuthorName, Books.pub_id,
Books.BooksOnHand, Books.Price
INTO BookPriceIncrease_ByMajor
FROM Majors, Books
GROUP BY Majors.MajorID, Majors.Description, Books.BookID,
Books.Title, Books.AuthorName, Books.pub_id,
Books.BooksOnHand, Books.Price;
GO
DROP PROCEDURE sp_PriceIncrease
Go
CREATE PROCEDURE sp_PriceIncrease(@MajorID int , @Percent int = 5)
AS UPDATE BookPriceIncrease_ByMajor
SET Price = Price + (Price*(@Percent/100))
UPDATE BookPriceIncrease_ByMajor
SET @MajorID = MajorID
GO
EXECUTE sp_PriceIncrease 1,10
GO
SELECT MajorID, BookID, Price FROM BookPriceIncrease_ByMajor;
GO