Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT PART OF AN EMAIL ADDRESS

Status
Not open for further replies.
Jan 23, 2003
26
US

HI,
What is the syntax in SQL to select part of an email address?

example:
testing@abcd.com

How would I create a SQL select statement to only select "testing" and not abcd.com.

Any help would be appreciated.

Thanks.
 
Hi,

Try this

select Substring(fldname,1,charindex('@',fldname)-1) from tbl

Sunil
 
Thanks, but I get this error:
Server: Msg 536, Level 16, State 4, Line 1
Invalid length parameter passed to the substring function.
 
Hi,

do u have NULL or blank fields in the table is yes
try this

select Substring(fldname,1,charindex('@',fldname)-1) from tbl where fldname is not null and fldname<> ''


Sunil
 
I would check that the address actually contained the @ symbol as this is what is causing the error:

Code:
select Substring(fldname,1,charindex('@',fldname)-1) from tbl where fldname LIKE '%@%'
--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top