1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| with rev (id, str)
as
(
select id, REVERSE(nom)
from Nom_Prenom_Agent
)
select n1.id, n1.nom
from Nom_Prenom_Agent n1
inner join rev on rev.id = n1.id
and (charindex(' ', str) <> 2 or substring(rev.str, charindex(' ', SUBSTRING(rev.str, 3, len(rev.str) - 3)) + 1, 1) <> substring(rev.str, 1, 1))
union all
select n2.id, substring(n2.nom, 1, LEN(n2.nom) - 2) nom
from Nom_Prenom_Agent n2
inner join rev on rev.id = n2.id
and charindex(' ', str) = 2 and substring(rev.str, charindex(' ', SUBSTRING(rev.str, 3, len(rev.str) - 3)) + 1, 1) = substring(rev.str, 1, 1); |
Partager