CTE re-creates the hierarchic structure. I tried this one
WITH CTEdns AS
(
select dns.dnsname, dns.alias, left(dns.alias, charindex('.', dns.alias)-1) as dns from dbo.dnsname as dns where zona='eni.it'
union all
select rec.dnsname, rec.alias, rec.alias as dns...