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
- updates num column in #temp @num
- updates @num @num + ntt
Comments
Post a Comment