• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Find "something" space "something"

I need to test a field and say does the field contain any value, then a space, then another value?

"west 3rd" should evaluate to true
"3rd" should evaluate to false
0
donnatronious
Asked:
donnatronious
  • 2
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hello donnatronious,

IF CHARINDEX ( ' ', 'ur String' ) >0
  SELECT 'true'
ELSE
SELECT 'False'



Aneesh R
0
 
harfangCommented:
As a criteria, this would be:

    WHERE TestField Like '% %'

As an expression, use

    SELECT ... , (TestField Like '% %') As MyTest, ...

Cheers!
(°v°)
0
 
Patrick MatthewsCommented:
Hello donnatronious,

With respect to all concerned, the answer you accepted does not answer the question as
written.  For example, what if the column value is just one or more spaces?  aneeshattingal's
expression will treat that as passing (as will Markus's).

Regards,

Patrick
0
 
harfangCommented:
Hello Patrick,

As a matter of fact, I had written a follow-up using Trim() to address that very issue, but couldn't find whether that is a valid MS-SQL function... Do you know?

(°v°)
0
 
Patrick MatthewsCommented:
Markus,

SQL Server 2000 does not have a single TRIM() function; instead it has RTRIM() and LTRIM() to
remove trailing or leading spaces, respectively.  As with the Access and VBA Trim() function,
neither of those truncate 2+ interior spaces to just one--which is something the native Excel
TRIM() function can do :)

I have not worked directly yet with SQL Server 2005, so I do not know whether it has a more
general trimming function...

Regards,

Patrick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now