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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select where a field contains @
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ldrenning
Starting Member

23 Posts

Posted - 05/31/2006 :  11:13:38  Show Profile  Reply with Quote
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 - 05/31/2006 :  11:19:17  Show Profile  Visit sshelper's Homepage  Reply with Quote
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

United Kingdom
1870 Posts

Posted - 05/31/2006 :  11:19:59  Show Profile  Visit mr_mist's Homepage  Reply with Quote
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. :)

Edited by - mr_mist on 05/31/2006 11:21:14
Go to Top of Page

ldrenning
Starting Member

23 Posts

Posted - 05/31/2006 :  11:24:20  Show Profile  Reply with Quote
Thanks everyone!
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22864 Posts

Posted - 05/31/2006 :  11:30:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
http://vyaskn.tripod.com/handling_email_addresses_in_sql_server.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000