I have following code in stored procedure. It was working before.

declare @mail_cd varchar(3),
@pointtype_id int, @mailcd varchar(3),@j int,@i int

select @mail_cd = 'WT'
select @i = charindex('WT',@mail_cd,1)

select @mailcd =''

select @i
if @i = 1
begin
select @mailcd = substring(rtrim(@mail_cd),1,2)
end
else
begin
select @mailcd = substring(rtrim(@mail_cd),1,1)
end

select @mail_cd,@mailcd

select @j = charindex('LF',@mail_cd,1)

if @j = 1
begin
select @mailcd = substring(rtrim(@mail_cd),1,2)
end
else
begin
select @mailcd = substring(rtrim(@mail_cd),1,1)
end

select @pointtype_id = code_id
from Code c,type ct
where c.type_id = ct.type_id
and ct.[name] = 'pointtype'
and code = @mailcd

select @mailcd,@pointtype_id


I get result

---- -----------
W 178

(1 row(s) affected)

instead of

---- -----------
WT 278

(1 row(s) affected)

Any idea what is wrong? Thanks in advance