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
 General SQL Server Forums
 New to SQL Server Programming
 Select where a field contains @

Author  Topic 

ldrenning
Starting Member

23 Posts

Posted - 2006-05-31 : 11:13:38
Is there a way in SQL Server to query for a character that is in a field? ... I have this old table before there was form validation, and I want to get the addresses out of the column that actually have an @.

I want to do something like this.

SELECT
email
FROM
xyz
WHERE
email contains '@'
AND
email contains '.'

any ideas? Will this work?

Thanks,
-L


sshelper
Posting Yak Master

216 Posts

Posted - 2006-05-31 : 11:19:17
You will use the LIKE function for this:

SELECT email FROM xyz WHERE email LIKE '%@%'

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2006-05-31 : 11:19:59
You could do similar, if your column is full text indexed -


USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "choc*" ')
GO

otherwise you'd be looking at charindex -


SELECT CHARINDEX ('@', columnname) FROM yourtable

OR in your case

SELECT * from yourtable
WHERE CHARINDEX ('@', columnname) > 0

-------
Moo. :)
Go to Top of Page

ldrenning
Starting Member

23 Posts

Posted - 2006-05-31 : 11:24:20
Thanks everyone!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-31 : 11:30:04
http://vyaskn.tripod.com/handling_email_addresses_in_sql_server.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -