You don't make it clear but I assume that the problem is that you are starting with a 10 character candidate prefix and if nothing matches you need to widen the search by making the search prefix less specific. Having found a prefix you then want to find the first code that uses that prefix. If this isn't what you're trying to achieve please rewrite the question.
declare @done bit
set @done = 0
declare @searchCLI varchar(10)
set @searchCLI = '123456789'
while @done=0 and len(@searchCLI) > 0
if exists(select dialprefix from Data_EE_Dials where dialprefix like @searchCLI)
begin
set @done = 1
end
if @done = 0
begin
set @searchCLI = substring(@searchCLI,1,len(@searchCLI)-1)
end
end
select top 1 *
from Data_EE_Codes as Codes
inner join Data_EE_Dials as Dials
on Dials.ChargeCategory = Codes.CallType
where dials.dialprefix like @searchCLI