select @i=(case when num=66 then @i+1 else @i end) from T
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)
from T
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)