Unix Technical Forum

Find website from email address

This is a discussion on Find website from email address within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I have 2 fields in a database: 'email' and 'website'. In the majority of cases, the website field ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:25 PM
Mintyman
 
Posts: n/a
Default Find website from email address

Hi,

I have 2 fields in a database: 'email' and 'website'.

In the majority of cases, the website field is not populated even though the
email address is. In 90% of cases, the website will be 'www.' followed by
whatever is after the '@' symbol in the email address.

Would anyone be able to help me with the SQL that would take whatever is
after the '@' sign in the email address, add it to 'www.' and populate the
'website' field?

Thanks!


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:25 PM
PBsoft
 
Posts: n/a
Default Re: Find website from email address

> Would anyone be able to help me with the SQL that would take whatever
> is after the '@' sign in the email address, add it to 'www.' and
> populate the 'website' field?


UPDATE yourtable
SET Site = SUBSTRING(yourtable.email, CHARINDEX('@', yourtable.email) + 1,
LEN(yourtable.email) - CHARINDEX('@', yourtable.email))

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skypebsoftsolution


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:25 PM
Dan Guzman
 
Posts: n/a
Default Re: Find website from email address

> Would anyone be able to help me with the SQL that would take whatever is
> after the '@' sign in the email address, add it to 'www.' and populate the
> 'website' field?


Here's one method:

UPDATE dbo.MyTable
SET website =
CASE WHEN CHARINDEX('@', email) > 0 AND CHARINDEX('@', email) + 1 <
LEN(email) THEN
'www.' + SUBSTRING(email, CHARINDEX('@', email) + 1, 255)
ELSE
website
END
WHERE
website IS NULL OR
website = ''

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Mintyman" <mintyman@ntlworld.com> wrote in message
news:f6gap5$qgb$1$8300dec7@news.demon.co.uk...
> Hi,
>
> I have 2 fields in a database: 'email' and 'website'.
>
> In the majority of cases, the website field is not populated even though
> the email address is. In 90% of cases, the website will be 'www.' followed
> by whatever is after the '@' symbol in the email address.
>
> Would anyone be able to help me with the SQL that would take whatever is
> after the '@' sign in the email address, add it to 'www.' and populate the
> 'website' field?
>
> Thanks!
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 03:25 PM
Mintyman
 
Posts: n/a
Default Re: Find website from email address

Cheers guys! Much appreciated )

"Mintyman" <mintyman@ntlworld.com> wrote in message
news:f6gap5$qgb$1$8300dec7@news.demon.co.uk...
> Hi,
>
> I have 2 fields in a database: 'email' and 'website'.
>
> In the majority of cases, the website field is not populated even though
> the email address is. In 90% of cases, the website will be 'www.' followed
> by whatever is after the '@' symbol in the email address.
>
> Would anyone be able to help me with the SQL that would take whatever is
> after the '@' sign in the email address, add it to 'www.' and populate the
> 'website' field?
>
> Thanks!
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:35 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com