dbTalk Databases Forums  

Select question

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Select question in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris
 
Posts: n/a

Default Select question - 03-09-2007 , 01:38 PM






Is there a way to select records that do not contain a certain
character string in char, vchar or text fields? For example records
where the email field does not contain the "@" character. Can't find
it in the BoL.

Chris


Reply With Quote
  #2  
Old   
matthewf_boi@yahoo.com
 
Posts: n/a

Default Re: Select question - 03-09-2007 , 03:03 PM






On Mar 9, 12:38 pm, "Chris" <cjscu... (AT) gmail (DOT) com> wrote:
Quote:
Is there a way to select records that do not contain a certain
character string in char, vchar or text fields? For example records
where the email field does not contain the "@" character. Can't find
it in the BoL.

Chris
CREATE TABLE MYTABLE (COL1 VARCHAR(80), COL2 VARCHAR(80))

INSERT INTO MYTABLE (COL1, COL2) VALUES ('1', 'Bob (AT) bob (DOT) com')
INSERT INTO MYTABLE (COL1, COL2) VALUES ('2', 'Bob.com')
INSERT INTO MYTABLE (COL1, COL2) VALUES ('3', 'mary (AT) bob (DOT) com')
INSERT INTO MYTABLE (COL1, COL2) VALUES ('4', 'Mary')

SELECT * FROM MYTABLE WHERE CHARINDEX('@', COL2) =0

Charindex is looking for the position # of the character specified.
If the character is not there, the charindex should be zero.

HTH
Matthew



Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Select question - 03-10-2007 , 02:44 AM



Chris (cjscully (AT) gmail (DOT) com) writes:
Quote:
Is there a way to select records that do not contain a certain
character string in char, vchar or text fields? For example records
where the email field does not contain the "@" character. Can't find
it in the BoL.
A second alternative to Matthew's:

SELECT ... FROM tbl WHERE col NOT LIKE '%@%'


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.