Tuesday, November 13, 2018

Sql Server Cursor

I had to write a sql server cursor.  I tend to put things into my blog so that I can keep them around for my own memory.  Here is one that I wrote:
begin
Declare @TournamentId bigint, @token uniqueidentifier
declare tourncursor cursor for select Tournamentid from Tournament where Token is null
open tourncursor
fetch next from  tourncursor into @TournamentId
while @@fetch_status = 0
begin
update Tournament set token = NEWID() where Tournamentid = @Tournamentid
fetch next from  tourncursor into @tournamentid

end
close tourncursor
deallocate tourncursor
end