I have to do this in SQL Server
I have data such as
Belo Horizonte , MG - Brazil
São Paulo , SP - Brazil
Barueri , SP - Brazil
Ferraz de Vasconcelos
I think this will do it... or a variation thereof to suit your needs. In this case it'll pick out the first pair of of uppercase letters.
with dataset as
(
select 'Belo Horizonte , MG - Brazil' as val union all
select 'São Paulo , SP - Brazil' as val union all
select 'Ferraz de Vasconcelos , SP - Brazil'
)
select Substring(val ,PatIndex('%[A-Z][A-Z] %' COLLATE LATIN1_gENERAL_BIN,val),3)
from dataset