Solved

Trim Everything After @ In Email Address

Posted on 2003-12-03
10
684 Views
Last Modified: 2008-03-17
I am trying to write a statement that will take everything in an email address from the @ and all characters to its right off of the returned value.

i.e. - thisisatest@testing123456789.com  in this case the only data that will be returned would be

        thisisatest
0
Comment
Question by:H-SC
  • 4
  • 4
10 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 9866573
Hi H-SC,

Select Left(EMailAddress,CharIndex('@',EMailAddress) -1) As Address From MyTable

Is one way, this finds the position of the @ and then returns the left portion of the field.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 1

Author Comment

by:H-SC
ID: 9866653
Thanks for the quick response.

When I run that statement it gives me an error "Invalid param passed to the substring function"
error #536
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9866694
The most likely situation is that one or more of the entries either contain no address or the address does not have the @ character in it. There are a number of ways to work around this, perhaps the easiest is to append an @ to the string in the first place which means you will get the entire address if no @ already present or the correct information if one is.

Select Left(EMailAddress + '@',CharIndex('@',EMailAddress + '@') -1) As Address From MyTable
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 1

Author Comment

by:H-SC
ID: 9866747
That is great.  I do not get errors on the last statement, however it only returns the first character in the email address.

i.e. - in my example of thisisatest@testing123456789.com would return "t"

any ideas?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9866782
I am using this just to prove the case:

declare @EmailAddress varchar(50)
Set @emailaddress = 'thisisatest@testing123456789.com'
Select Left(@EMailAddress + '@',CharIndex('@',@EMailAddress + '@') -1) As Address

Which is returning the correct value.
0
 
LVL 1

Author Comment

by:H-SC
ID: 9866860
I ran the last one and it works.  Will the declare or set change any data or write back?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9866900
No not at all, this is unconnected to any table and just to demonstrate the principal. If the equivalent statement using your table and its fieldname(s) still fails then there must be something different with the data in the column that is causing this problem.
0
 
LVL 1

Author Comment

by:H-SC
ID: 9866935
GREAT!  will I need to do a different statement that will return real-time values.  The last one returned one row; "thisisatest"
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 9901094
Question closed and points refunded

PashaMod
CS Moderator
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question