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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -