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
 [Resolved] Search For Spaces In a Field

Author  Topic 

cnbhold
Starting Member

43 Posts

Posted - 2011-01-06 : 00:13:27
I have a table that contains a field called Keyword. This field should only contain one word. However, users have been typing in more than one word.

Incorrect Data Entry

ID Identity_ID Condition Keyword
1 1234 And Microsoft Word

Correct Data Entry

ID Identity_ID Condition Keyword
1 1234 And Microsoft
2 1234 And Word

This table contains thousand of records and I need to run a query that shows me all the records that have more that one word in the Keyword field.

Select *
From Keyword
Where Keyword Like ???

Angel

cnbhold
Starting Member

43 Posts

Posted - 2011-01-06 : 00:20:56
I figured it out

Select *
From Keyword
Where Keyword Like '% %'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 01:16:18
this will even return cases where you have some leading or trailing spaces in single word

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 01:17:01
may be this?


Select *
From Keyword
Where LTRIM(RTRIM(Keyword)) Like '% %'



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cnbhold
Starting Member

43 Posts

Posted - 2011-01-10 : 10:00:32
Thanks visakh16.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-10 : 10:41:07
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -