sql server - how to iterate over an cursor -


i have select statement returns single row. after have written cursor me @@fetch_status -1 not go inside cursor now

open cur_mkt     print @init  while (@init = 0)       begin       fetch next cur_mkt        @desc,       @divisions       print @@fetch_status if (@@fetch_status =-1)       break    

is there way can go inside cursor, please me out.

it doesn't sound need cursor (which should try avoid anyway). if you're determining presence of result do:

select @desc = desc, @divisions = divisions yourtable id = 1  if ( @@rowcount > 0 )     begin         -- row found     end 

so recommend not using cursors.

to directly answer question, way use cursors/iterate round results follows:

declare @a integer  declare cur_mkt cursor select 1  union select 2  open cur_mkt fetch next cur_mkt @a  while (@@fetch_status = 0)     begin         print @a             fetch next cur_mkt @a     end  close cur_mkt deallocate cur_mkt 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -