Get Multiple Values in SQL Server Cursor -
i have cursor containing several columns row brings process @ once. notice of examples i've seeing on how use cursors show them assigning particular column cursor scalar value 1 @ time, moving next row,
e.g.
open db_cursor fetch next db_cursor @name while @@fetch_status = 0 begin --do stuff @name scalar value, next row cursor fetch next db_cursor @name end
what want know if it's possible following:
open db_cursor fetch next db_cursor; while @@fetch_status = 0 begin set @myname = db_cursor.name; set @myage = db_cursor.age; set @myfavoritecolor = db_cursor.favoritecolor; --do stuff scalar values fetch next db_cursor; end
help appreciated.
this should work:
declare db_cursor cursor select name, age, color table; declare @myname varchar(256); declare @myage int; declare @myfavoritecolor varchar(40); open db_cursor; fetch next db_cursor @myname, @myage, @myfavoritecolor; while @@fetch_status = 0 begin --do stuff scalar values fetch next db_cursor @myname, @myage, @myfavoritecolor; end; close db_cursor; deallocate db_cursor;
Comments
Post a Comment