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_temp*1.1
ENDI am not too big into the use of cursors in SQL, but do you intend to pass a cursor to the stored procedure? Can you do this?
What error messages do you get when you try to use this?
No comments:
Post a Comment