Check if starting characters of a string are alphabetical in T-SQL

后端 未结 2 1888
无人共我
无人共我 2021-02-12 03:41

Is it possible, just using TSQL, to check if the first two characters of a varchar field are alphabetical?

I need to select from my_table only the rows havi

2条回答
  •  無奈伤痛
    2021-02-12 04:45

    You don't need to use regex, LIKE is sufficient:

    WHERE my_field LIKE '[a-zA-Z][a-zA-Z]%'
    

    Assuming that by "alphabetical" you mean only latin characters, not anything classified as alphabetical in Unicode.

    Note - if your collation is case sensitive, it's important to specify the range as [a-zA-Z]. [a-z] may exclude A or Z. [A-Z] may exclude a or z.

提交回复
热议问题