Find ONLY Capital Letters in word through IN SQL Server query

前端 未结 5 831
名媛妹妹
名媛妹妹 2020-12-11 19:50

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          


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 20:22

    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
    

提交回复
热议问题