我的MSQL服务器中有电子邮件列,我需要修剪电子邮件,只留下域名。因此,包括“@”在内的@左侧的所有内容都需要消失。同时我只需要一个域,所以没有重复..
示例:
Column name = Domains
TEST@EXAMPLE.COM
TEST2@EXAMPLE.NET
TEST3@EXAMPLE.COM
.
.
.
------- from - >到-------
Column name = Domains
EXAMPLE.COM
EXAMPLE.NET
答案 0 :(得分:0)
DECLARE @foo TABLE (foo varchar(100));
INSERT @foo
VALUES
('TEST@TESTCOMPANY.COM'),
('TEST2@TESTCOMPANY2.COM'),
('TEST3@TESTCOMPANY.COM')
--fun version
SELECT DISTINCT
PARSENAME(REPLACE(foo, '@', '.'), 2) + '.' + PARSENAME(foo, 1)
FROM
@foo
--deals with more than 3 dots
--8000 allows us to *not* know the actual string length. It "just works"
SELECT DISTINCT
SUBSTRING(foo, CHARINDEX('@', foo)+1, 8000)
FROM
@foo