我在为学校项目创建游标时遇到问题。我想根据他们的最爱给人们建议。
ALTER PROCEDURE [dbo].[PrintSongsByGenre]
AS
DECLARE @UserID AS INT;
DECLARE @Genre AS VARCHAR(50);
DECLARE @GenreCursor AS CURSOR;
SET @GenreCursor = CURSOR FOR
SELECT MAX(s.genre)
FROM Song s
LEFT JOIN Favorite_Song fs on s.song_ID = fs.song_ID
WHERE fs.user_ID = @UserID;
OPEN @GenreCursor;
DELETE FROM Suggestions
WHERE userID = @UserID;
FETCH NEXT FROM @GenreCursor INTO @Genre;
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO Suggestions ([userId], genre)
VALUES (@UserID, @Genre)
END;
CLOSE @GenreCursor;
DEALLOCATE @GenreCursor;
我已经创建了上面的内容,它已经在旧版本的SQL Server上运行,但它不再起作用了。存储过程不再具有参数。
现在我不知道如何重新创建这些参数。