您可以递归使用cte去除字符串。
declare @T table (id int, [text] nvarchar(max))insert into @T values (1, 'Peter (Peter@peter.de) and Marta (marty@gmail.com) are doing fine.')insert into @T values (2, 'Nothing special here')insert into @T values (3, 'Another email address (me@my.com)');with cte([text], email)as( select right([text], len([text]) - charindex(')', [text], 0)), substring([text], charindex('(', [text], 0) + 1, charindex(')', [text], 0) - charindex('(', [text], 0) - 1) from @T where charindex('(', [text], 0) > 0 union all select right([text], len([text]) - charindex(')', [text], 0)), substring([text], charindex('(', [text], 0) + 1, charindex(')', [text], 0) - charindex('(', [text], 0) - 1) from cte where charindex('(', [text], 0) > 0)select emailfrom cte
结果
emailPeter@peter.deme@my.commarty@gmail.com
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)