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

后端 未结 2 1866
无人共我
无人共我 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:39
    select * from my_table where my_field Like '[a-z][a-z]%'
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题