[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Email Domain Extraction

Hello peeps!
Am in desperate need to extract all domain names from an email field - so mel@mel.com will return @mel.com - any ideas on what the sql code will be to do this?
Thanks

0
delic8te
Asked:
delic8te
  • 3
  • 2
  • 2
1 Solution
 
HuyBDCommented:
Try this

select right(email,len(email)-charindex('@',email))
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
DECLARE @email varchar(400)
SET @Email = 'aneeshattingal@hotmail.com'
SELECT SUBSTRING(@Email, Charindex('@',@Email)+1,Len(@Email)-Charindex('@',@Email)+1)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
if you need '@' then


DECLARE @email varchar(400)
SET @Email = 'aneeshattingal@hotmail.com'
SELECT SUBSTRING(@Email, Charindex('@',@Email),Len(@Email)-Charindex('@',@Email)+1)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
delic8teAuthor Commented:
thanks - however, I need this to be an update query......???
0
 
HuyBDCommented:

update yourtable set domain=right(email,len(email)-charindex('@',email))
0
 
delic8teAuthor Commented:
yep - of course - have a silly moment - just figured it out myself - thanks again :)
0
 
delic8teAuthor Commented:
how about address lines?? extracting a postcode from a address?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now