exam is coming.i still feel headache about procedure using cursor.
here is example:
Q.Create a cursor stored procedure called PriceChange to read the title id and price from the titles tables which will return the information as a cursor output. Use the PriceChange stored procedure to increase the price in the titles table by 10% using a cursor. If the price is null, set the price to $9.99. (pubs database)
i try to do this way but fail,can somebody help me?thanks.
CREATE PROCEDURE PriceChange
(@titles_cursor CURSOR VARYING OUTPUT)
AS
SET @titles_cursor = CURSOR
FORWARD_ONLY STATIC FOR
SELECT title_id,
price
FROM titles
OPEN @titles_cursor
GO
DECLARE @MyCursor CURSOR,
@title_id_temp varchar(6),
@price_temp money
EXEC PriceChange @titles_cursor= @MyCursor OUTPUT
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM @MyCursor INTO @title_id_temp, @price_temp
IF @price_temp IS NULL
SET price=9.99
ELSE
SET price=@price_te mp*1.1
END
here is example:
Q.Create a cursor stored procedure called PriceChange to read the title id and price from the titles tables which will return the information as a cursor output. Use the PriceChange stored procedure to increase the price in the titles table by 10% using a cursor. If the price is null, set the price to $9.99. (pubs database)
i try to do this way but fail,can somebody help me?thanks.
CREATE PROCEDURE PriceChange
(@titles_cursor CURSOR VARYING OUTPUT)
AS
SET @titles_cursor = CURSOR
FORWARD_ONLY STATIC FOR
SELECT title_id,
price
FROM titles
OPEN @titles_cursor
GO
DECLARE @MyCursor CURSOR,
@title_id_temp varchar(6),
@price_temp money
EXEC PriceChange @titles_cursor= @MyCursor OUTPUT
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM @MyCursor INTO @title_id_temp, @price_temp
IF @price_temp IS NULL
SET price=9.99
ELSE
SET price=@price_te mp*1.1
END
Comment