Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Trim a string

Author  Topic 

mshsilver
Posting Yak Master

112 Posts

Posted - 2013-11-13 : 11:09:02
Hi,

I have a field in a database called emailaddress. I want a query that show all the characters including the @ to the right. I have tried various things and i can't get the result i need.

So say the email was john.smith@yahoo.com and i want a query that just shows @yahoo.com or @anything.com etc etc for all the record in a table. What would the correct function be, an example would be great along with an explanation so i understand it.

Many thanks

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-11-13 : 16:21:03
SELECT SUBSTRING(column_name, CHARINDEX('@', column_name), 200)
Go to Top of Page

mshsilver
Posting Yak Master

112 Posts

Posted - 2013-11-14 : 02:04:28
That is perfect, thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-14 : 02:24:43
[code]
SELECT STUFF(emailaddress,1,CHARINDEX('@',emailaddress)-1,'') FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -