IndexOf function in T-SQL

前端 未结 4 1156
广开言路
广开言路 2020-12-09 00:43

Given an email address column, I need to find the position of the @ sign for substringing.

What is the indexof function, for strings in T-SQL?

L

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 01:06

    One very small nit to pick:

    The RFC for email addresses allows the first part to include an "@" sign if it is quoted. Example:

    "john@work"@myemployer.com
    

    This is quite uncommon, but could happen. Theoretically, you should split on the last "@" symbol, not the first:

    SELECT LEN(EmailField) - CHARINDEX('@', REVERSE(EmailField)) + 1
    

    More information:

    http://en.wikipedia.org/wiki/Email_address

提交回复
热议问题