我在列中有電子郵件 ID,我只想獲取域名。
例如:我有[email protected]或[email protected]我只想要hp-dell, lenovo。
有人可以在 SQL Server 中幫助解決這個問題嗎?
uj5u.com熱心網友回復:
SELECT SUBSTRING(@email,
CHARINDEX('@', @email) 1,
LEN(@email) - CHARINDEX('@', @email) - CHARINDEX('.', REVERSE(@email)))
uj5u.com熱心網友回復:
嘗試這個
declare @email nvarchar(200)
set @email = '[email protected]'
declare @startIndex int
declare @endIndex int
select @startIndex = charindex('@', @email, 1) 1
select @endIndex = len(@email) - (charindex('.', reverse(@email) , 1) -1)
print @startIndex
print @endIndex
print substring(@email, @startIndex, @endIndex - @startIndex) -- will print testmine.abc
uj5u.com熱心網友回復:
從頂級域創建一個目錄 - https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains 然后通過 REPLACE() 函式解決您的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317024.html
標籤:sql-server 解析 子串
