• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • 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

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

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