2 回答

TA贡献1878条经验 获得超4个赞
你的语句需要修改 因为你在执行
select @id=(select top 1 cyid from chengyuan where cyid not in(
select top (@icy-1) cyid from chengyuan order by cyid asc) order by cyid asc),
@yingfu= ((select cyreturn from chengyuan where cyid=@id)-(select cyoffer from chengyuan where cyid=@id))
这一段的时候 第一次循环时@id在(select cyreturn from chengyuan where cyid=@id )里面为null值的
所以@yingfu 也等于null 当然后面的update语句@id才是第一次查询出来的值
等到第二次循环后在(select cyreturn from chengyuan where cyid = @id) @id等于第一次循环的值后面的update语句@id才是第二次查询出来的值
(注意:不管declare @icy int在循环内还是循环前,值一样)

TA贡献1772条经验 获得超5个赞
select 、update等SQL语句都是对行同时操作的。如一个表test(a,b)
a b
1 2
update test set a=b,b=a where a=1后,
结果:
a b
2 1
- 2 回答
- 0 关注
- 1596 浏览
添加回答
举报