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 關注
- 1634 瀏覽
添加回答
舉報
