declare @outlet int
declare @outletstate char(2)
declare @do_time smalldatetimedeclare ac cursor for select outlet,outletstate,do_time from #t1 open acfetch next from ac into @outlet,@outletstate, @do_time
WHILE @@FETCH_STATUS = 0
BEGIN
if convert(int,(@do_time -@start_date))/7=0
begin
update cm_show_state set sp1=@outletstate
where outlet =@outlet
return --已经return了,后边的代码自然是不会执行
end
if convert(int,(@do_time -@start_date))/7=1
begin
update cm_show_state set sp2=@outletstate
where outlet=@outlet
return --同上
end
.....
fetch next from ac into @outlet,@outletstate, @do_time
END
CLOSE ac
DEALLOCATE ac
declare @outletstate char(2)
declare @do_time smalldatetimedeclare ac cursor for select outlet,outletstate,do_time from #t1 open acfetch next from ac into @outlet,@outletstate, @do_time
WHILE @@FETCH_STATUS = 0
BEGIN
if convert(int,(@do_time -@start_date))/7=0
begin
update cm_show_state set sp1=@outletstate
where outlet =@outlet
return --已经return了,后边的代码自然是不会执行
end
if convert(int,(@do_time -@start_date))/7=1
begin
update cm_show_state set sp2=@outletstate
where outlet=@outlet
return --同上
end
.....
fetch next from ac into @outlet,@outletstate, @do_time
END
CLOSE ac
DEALLOCATE ac
declare @outletstate char(2)
declare @do_time smalldatetimedeclare ac cursor for select outlet,outletstate,do_time from #t1 open acfetch next from ac into @outlet,@outletstate, @do_time
WHILE @@FETCH_STATUS = 0
BEGIN
if convert(int,(@do_time -@start_date))/7=0
begin
update cm_show_state set sp1=@outletstate
where outlet =@outlet
--return
end
if convert(int,(@do_time -@start_date))/7=1
begin
update cm_show_state set sp2=@outletstate
where outlet=@outlet
--return
end
.....
fetch next from ac into @outlet,@outletstate, @do_time
END
CLOSE ac
DEALLOCATE ac
可是他是随机取的啊 ,我希望它从第一条开始,不知道该怎么写。
declare ac cursor for select outlet,outletstate,do_time from #t1
--for forward_only
如果加上for forward_only会显示出错,不知道为什么
就是,我的数据@start_date='2005-08-01'
而do_time 的值有 '2005-08-13'和'2005-08-20'
也就是 说当取到do_time ='2005-08-13'时应该修改sp2的state,
do_time ='2005-08-20'时应该修改sp3的state
可是却没有修改sp2的值,只是修改了sp3的值
为什么啊??
还有@start_date从哪里来的?
update cm_show_state set sp2=@outletstate
where current of T_cursor
因为游标的指针指向了这一行,如果满足条件,那么就可以更新,如果不行,那么指针下移就可以了。
如果你才用参数的方式,一旦出现重复参数,那么就会涉及到其他的行了!