简体   繁体   English

从 sql 中的字符串中提取 Email 域

[英]Extracting Email Domain from string in sql

I have string something like this我有这样的字符串

  1. 'myname' <myname@mydomain.com>

or like this或者像这样

  1. myname@mydomain.com

I want to extract domain from both kind of strings我想从两种字符串中提取域

For 2nd I can do somthing like this第二我可以做这样的事情

select RIGHT(email, LEN(email) - CHARINDEX('@', email))

but same is not working for 1st string.但同样不适用于第一个字符串。

Also I do not know in which format email address will come另外我不知道email地址会以哪种格式出现

I am using Sql Server 2014.我正在使用 Sql 服务器 2014。

You can use stuff() and replace() :您可以使用stuff()replace()

select replace(stuff(email, 1, charindex('@', email), ''), '>', '')

Here is a db<>fiddle. 是一个 db<>fiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM