如果存在记录(比如num=66)就把@i增加1declare @i
set @i=0表格如下:
id  num 
01  22
02  11
03  33
04  66
..  ..

解决方案 »

  1.   

    select @i=(case when num=66 then @i+1 else @i end)
    from T
      

  2.   

    create table T(id char(2), num int)
    insert T select '01',  22
    union all select '02',  11
    union all select '03',  33
    union all select '04',  66declare @i int
    set @i=0
    select @i=(case when num=66 then @i+1 else @i end)
    from Tselect @i--result
    ----------- 
    1(1 row(s) affected)