Update statement and cursor in SQL Server -


i'm little confused below update statement. example if @num = 1 , ntt = 4. while using cursor want use initial value of num .i.e 1. i'm receiving incremented value 5. doing wrong ? thanks, appreciate it.

update #temp set num = @num,      @num = @num + ntt  declare cur cursor local forward_only dynamic      select yr, id, num #temp  open cur fetch cur @yr, @id, @num   while @@fetch_status = 0      begin      update #temp2      set tran_id = @num,          @num = @num +1      ...........       fetch cur @yr, @id, @num end 

the update 2 things determined in set

  1. updates num column in #temp @num
  2. updates @num @num + ntt


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -