Sorry if this is a dumb question, but I am new to SQL Server and trying a simple cursor. Works fine the first time I execute, but then @@Fetch_Status stays at -1 and it will not work again. If I disconnect and then connect it will work once again. What I am doing wrong
declare
@entityid int, @datafrom nvarchar (255),@datato
nvarchar (255), @updatedate datetime
declare
statustime1 cursorlocal
scroll staticfor
select
audit.entityid, audit.datafrom, audit.datato, audit.updatedatefrom
audit , orderswhere
audit.entityid = orders.orderidand
audit.entitytypeid = 4order
by orders.orderid, audit.updatedate descopen
statustime1While
@@fetch_status = 0 Begin fetch next from statustime1 into @entityid, @datafrom, @datato, @updatedate print @entityid endclose
statustime1deallocate
statustime1go