Basit Cursor Örneği

Basit Cursor Örneği hakkında detaylı bilgi, örnekler ve en iyi uygulamalar bu rehberde.

Temmuz 18, 2023

Basit Cursor Örneği

Bu, SQL Server Cursor’un en basit örneğidir. Bunu çoğu zaman T-SQL’imizde herhangi bir Cursor kullanımı için kullanıyoruz.

 

DECLARE @AccountID INT
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
SELECT Account_ID
FROM Accounts
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @AccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
END
CLOSE @getAccountID
DEALLOCATE @getAccountID