からドメインのテキストを抽出します。誰もこれを達成するためにsubstring
を書く方法を知っていますか?は私がMicrosoft SQL Serverの中で働いています<code>[email protected]</code></p> <p>から<code>espn</code>を抽出する方法を見つけることを期待していますEmailAddressの
ありがとうございます!
からドメインのテキストを抽出します。誰もこれを達成するためにsubstring
を書く方法を知っていますか?は私がMicrosoft SQL Serverの中で働いています<code>[email protected]</code></p> <p>から<code>espn</code>を抽出する方法を見つけることを期待していますEmailAddressの
ありがとうございます!
これは動作するはずです:あなたはこのを探している
select SUBSTRING(
@email, --input string
charindex('@', @email) + 1, --character just after the @
charindex('.', @email, charindex('@', @email)) - charindex('@', @email) - 1 --distance between @ and the first . following it
)
。この
select SUBSTRING(
'[email protected]', --input string
charindex('@', '[email protected]') + 1,
(len('[email protected]')-charindex('@', '[email protected]'))-4
)
後にドメインの最初の部分を返す必要があります有効なemailAddressではない値の場合はNULL
(またはそこに置いたもの)を返します。無効な値eが発生しました。
DECLARE @emailAddress TABLE (emailAddress VARCHAR(255))
INSERT @emailAddress (emailAddress)
VALUES ('[email protected]'),
('[email protected]'),
('notanemailaddress')
SELECT IIF(emailAddress LIKE '%@%.%', -- Confirm it has valid structure
SUBSTRING(emailAddress,
CHARINDEX('@',emailAddress)+1,
CHARINDEX('.',emailAddress,CHARINDEX('@',emailAddress))-(CHARINDEX('@',emailAddress)+1)), --Extract the domain
NULL) -- Provide default value if not an emailAddress
AS emailDomain
FROM @emailAddress
このアカウントを試す
Select substring(@email,charindex('@', @email)+1,
charindex('.',right(@email,len(@email) - charindex('@', @email)))-1)
メールアドレスは、前.
複数回含めることができ、@
後、これは@
なぜこれが有用なのか不思議です。 – DavidG