Blog Post

Cursor Dynamic SQL

,

Today was working on SQL Server cursor standard cursor deification would be like this: sqlcursor from (Azure Data Studio) ———————————————————————————————————————– — Declare a cursor for a Table or a View ‘TableOrViewName’ in schema ‘dbo’ DECLARE @ColumnName1 NVARCHAR(50), @ColumnName2 NVARCHAR(50) DECLARE db_cursor CURSOR FOR SELECT name FROM dbo.TableOrViewName OPEN db_cursor FETCH NEXT FROM db_cursor INTO @ColumnName1, @ColumnName2 WHILE @@FETCH_STATUS = 0 BEGIN     — add instructions to be executed for every rows SELECT @db_nm     FETCH NEXT FROM db_cursor INTO Sys.Databases END CLOSE db_cursor DEALLOCATE db_cursor GO   … Continue reading ?

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating