I have a stored procedure with a table input. I want to somehow loop through the rows of that table. I'm not sure how you do this sort of thing in SQL.
Here is what I am trying to do, in pseudo-SQL:
CREATE PROCEDURE RearrangePuzzles
ChangedPuzzles table(
OldDifficulty nvarchar(50),
OldIndex int,
NewDifficulty nvarchar(50),
NewIndex int
)
AS
FOREACH Row IN ChangedPuzzles
BEGIN
UPDATE Puzzles
SET Index = Row.NewIndex,
Difficulty = Row.NewDifficulty
WHERE Index = Row.OldIndex AND
Difficulty = Row.OldDifficulty
END
This, of course, is not valid SQL. How can I write a query with the desired functionality in SQL?