Removing @companyname from e-mail address field?

  • This seems to me to be a really simple thing but I am stumped.

    I am going to create login names by removing the @companyname.com from people's e-mail addresses. The company names are all different so it isn't as easy as just removing a known set of characters. Any ideas? Thanks!

  • Pam Pinnacle (3/26/2008)


    This seems to me to be a really simple thing but I am stumped.

    I am going to create login names by removing the @companyname.com from people's e-mail addresses. The company names are all different so it isn't as easy as just removing a known set of characters. Any ideas? Thanks!

    Assuming that the @ character doesn't appear anywhere else in the email address and assuming it appears once you could do something like this:

    select substring(EmailAddress,1,charindex('@',EmailAddress)-1)

    --or if you want to update an existing table

    update my_table

    set login = substring(EmailAddress,1,charindex('@',EmailAddress)-1)

    Hope that helps.

  • try

    select substring(@email, 1, charindex('@', @email)-1)

    Dragos

  • Thanks so much! Those did the trick

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply