select distinct a.person, dbo.FormatNameA(p.Name), dbo.FormatNameA(p.FirstName) from PersonAlias a join Person p on p.id=a.Person where (a.Name like N'Lem' or a.NameA like N'Lem%' or a.NameB like N'Lem%') and a.FirstName like N'Stanisław%'
The EXECUTE permission was denied on the object 'FormatNameA', database 'xtrans', schema 'dbo'.