I have a table and in this one, a post column. What I need is for a query to show only the domains, that is, hotmail.com
, gmail.com
, etc ..
SELECT correo FROM cliente
I have a table and in this one, a post column. What I need is for a query to show only the domains, that is, hotmail.com
, gmail.com
, etc ..
SELECT correo FROM cliente
We can take advantage of @
as separator character, and stay with the word to the right of it. We could do it like this:
DECLARE @correo VARCHAR(255)
SELECT @correo = '[email protected]'
SELECT SUBSTRING(@correo, CHARINDEX('@', @correo)+1,LEN(@correo))
----------
"mail.com"
We searched with CHARINDEX()
the position of @
and cut from that place + 1 to the end of the chain with SUBSTRING()
. Taking it to your example would be:
SELECT SUBSTRING(correo, CHARINDEX('@', correo)+1,LEN(correo))
FROM cliente