Stripping a string

  • Hey Guru's

    Quick question.  I have several a database with several names and email addresses.  Some of the email address are with a name.  Just for the purpose of a query I would like to populate the name field with the string of an email prior to the @ symbol (only the name field is null)

    Ex.

    wow@there.com

    I would like to strip "wow" and put it into the name column if the name value is null

    I hope this makes sense.  Thanks

    Shane

  • ISNULL( name, case when CHARINDEX('@', email, 1) = 0 then '' else LEFT(email, CHARINDEX('@', email, 1) - 1) end ) AS name

     

Viewing 2 posts - 1 through 1 (of 1 total)

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