select id,da,
(case flag1+flag2 when 0 then 0 when 10 then 2 when 11 then 5 else 0 end) as df
from (
select a.id,a.da,case when b.fz is null then 0 else 1 end as flag1,
case when c.fz is null then 0 else 10 end as flag2
from table1 a
left join table2 b on a.id=b.id and a.da=b.ckda
left join table2 c on a.id=b.id and charindex(substring(a.da,1,1),c.ckda)<>0
) t