我这样写的IF语句错在哪里呢?请大哥大姐们帮帮忙
declare @i_1 int,@i_2 int,@i_3 int,@i_4 int,@i_5 int,
@i_6 int,@i_7 int,@i_8 int,@i_9 int,@i_0 int,@k int,@a datetime,@b varchar,@c varchar
select @i_1=0,@i_2=0,@i_3=0,@i_4=0,@i_5=0,@i_6=0,@i_7=0,@i_8=0,@i_9=0,@i_0=0,@b='',@c='',@k=0
declare kk cursor for
select date_1,code,number_1 from sixone where code='5065'
open kk
fetch next from kk into @a,@c,@b
while @@fetch_status=0
begin
set @k=0
while @k<=6
begin
if substring(@b,@k+1,1)='0'
begin
set @i_0=@i_0+1
end
if substring(@b,@k+1,1)='1'
begin
set @i_1=@i_1+1
end
if substring(@b,@k+1,1)='2'
begin
set @i_2=@i_2+1
end
if substring(@b,@k+1,1)='3'
begin
set @i_3=@i_3+1
end
if substring(@b,@k+1,1)='4'
begin
set @i_4=@i_4+1
end
if substring(@b,@k+1,1)='5'
begin
set @i_5=@i_5+1
end
if substring(@b,@k+1,1)='6'
begin
set @i_6=@i_6+1
end
if substring(@b,@k+1,1)='7'
begin
set @i_7=@i_7+1
end
if substring(@b,@k+1,1)='8'
begin
set @i_8=@i_8+1
end
if substring(@b,@k+1,1)='9'
begin
set @i_9=@i_9+1
end
print substring(@b,@k+1,1)
set @k=@K+1
end
fetch next from kk into @a,@c,@b
end
close kk
deallocate kk
select @i_0 as '0',@i_1 as '1',@i_2 as '2',@i_3 as '3',@i_4 as '4',@i_5 as '5',@i_6 as '6',@i_7 as '7',@i_8 as '8',@i_9 as '9'
select * from sixone where code='5065'