表:
cardid  cardnum   mask      isvalid
97163  1010000 0000 0
97164  10010001 4237 0
97165  10010002 4255 0
97166  10010003 1648 0
97167  10010004 4115 0
97168  10010005 8565 0
97169   10010006 7067 0
。。
存储过程
CREATE PROCEDURE usp3_EditCardnum
@cardnum nvarchar(50),
@cardid int AS
declare @n bigint
declare @count bigint
select count(*) from ele_cardnum
declare @_value bigint
update ele_cardnum set cardnum = @cardnum where cardid=@cardid
if(@_value>0)
begin
set @n=1
while @n<@count
begin
update ele_cardnum set cardnum=@cardnum+@n where cardid=@cardid+@n
end
end
GO可是存储过程中的while循环每执行,有哪位高手指点下,谢谢!

解决方案 »

  1.   

    啊,发现了,你的@count根本没给值就用了啊, 它是0啊
      

  2.   

    declare @count bigint
    select @count =count(*) from ele_cardnum
      

  3.   

    @_value没赋值,始终为null
    @count 没赋值,始终为null
    @n只初始化了一下,没有步进
      

  4.   

    while @n<@count
    begin
    update ele_cardnum set cardnum=@cardnum+@n where cardid=@cardid+@n
    SET @n=@n+1
    end
      

  5.   

    放update修改成功的值(update ele_cardnum set cardnum = @cardnum where cardid=@cardid)