Advertisement

07.02.2008 at 02:38PM PDT, ID: 23535220
[x]
Attachment Details

loop doesn't stop

Asked by ewang1205 in MS SQL Server

Tags: sql server

How come the following loop doesn't stop?  I just want to update the first row, but the procedure keeps going forever.  Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
alter proc  test as 
 
declare   @temp_salary  integer , 
@emp_no	integer ,
@salary integer 
declare cur_emp CURSOR for select emp_no, salary from emp order by emp_no
 
 
open cur_emp
 
fetch next from cur_emp  into @emp_no, @salary
 
while @@fetch_status =0 
 
begin
 
 
if @emp_no =1  
 
begin
update emp set rem_salary = 1000 - salary  where emp_no = @emp_no
print '2 emp no is ' 
end
 
 
end
close cur_emp
deallocate  cur_emp
 
commit
[+][-]07.02.2008 at 02:41PM PDT, ID: 21920970

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: sql server
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628