Using the LIKE keyword with range values to specify the dash

  • Hi I am trying to use a query to find values in a specified field which have spaces.  I am sure there is a much easier way to do this than I am attempting.  Here is the code I am using presently.

    MyField like  '%_ [A-Z,_,0-9]%'

    This works on most items but I want to include all values i.e. -,@,# etc.  The wild card % alone does not work for my purposes as it will return values with nothing trailing a blank which I dont want.  I want the query to return values like Fred Johnson, as opposed to Fred.  Using -- MyField like  '% %' will return both values presented before.

    I hope this is not too confusing as a question?

    Thanks to anyone who can help.

  • Not sure about what system (or settings) you have but:

    select *

    from

    (select 'Fred Johnson' mycol

    union all select 'Fred') data

    where mycol LIKE '% %'

    Returns *only* 'Fred Johnson' to me


    * Noel

  • You may have problems with the trailing spaces if your MyField is CHAR datatype not VARCHAR. In this case try using RTRIM(MyField) LIKE '% %'.

    This should help. 

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

  • Thanks very much I knew there had to be a simpler way.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply