Fetch next into cursor : Fetch Data « Cursor « SQL Server / T-SQL






Fetch next into cursor

 



DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
   SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
      WHERE TABLE_TYPE = 'BASE TABLE'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
   PRINT @TableName
   FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
GO

 








Related examples in the same category

1.FETCH value from a cursor