SELECT
substring(@email , 0 , CHARINDEX('.' , @email)) ,
substring(@email , CHARINDEX('.',@email)+1 , CHARINDEX('@' , @email) - CHARINDEX('.' , @email)-1),
substring(@email , CHARINDEX('@' , @email) , LEN(@email) - CHARINDEX('@' , @email)+1)
from employee;
與您的電子郵件列名
更簡單版本--replace @email明白:
DECLARE @email NVARCHAR(30) = '[email protected]';
DECLARE @dot INT =CHARINDEX('.' , @email);
DECLARE @atrate INT =CHARINDEX('@' , @email);
DECLARE @len INT =LEN(@email);
SELECT
substring(@email , 0 , @dot),
substring(@email , @dot+1 , @atrate - @dot-1),
substring(@email, @atrate , @len - @atrate+1);
醜陋的問題。像「jon.m.skeet @ google.co.uk」這樣的邊緣案例呢? –
什麼是SQL Server版本? –
以及如果電子郵件以姓氏而不是名字開頭,該怎麼辦? – GuidoG