0

我有这种情况:

John Doe johndoe@email.com
John johndoe@email.com

我想要的只是解析如下:

John Doe
John

换句话说,仅删除电子邮件地址。

我试过这个:

SELECT
                (CASE WHEN CHARINDEX(‘ ‘, REVERSE(column1)) > 0 THEN Left(column1, CHARINDEX(‘ ‘, REVERSE(column1)) – 1)
                ELSE column1
                END) AS column1
FROM Book1
4

2 回答 2

1

你在正确的轨道上......只需添加 len 函数并删除“负 1”

SELECT  (CASE WHEN CHARINDEX(' ', REVERSE(column1)) > 0 THEN Left(column1, len (column1) - CHARINDEX(' ', REVERSE(column1)))
                ELSE column1
                END) AS column1
FROM Book1
于 2013-10-04T20:27:11.597 回答
0
DECLARE @Str VARCHAR(MAX) = 'John Doe johndoe@email.com'


 SELECT LEFT(@Str, LEN(@Str) - LEN(REVERSE(SUBSTRING(REVERSE(@Str), 1, CHARINDEX(' ', REVERSE(@Str)) - 1))))
于 2013-10-04T20:28:21.603 回答