Wildcard and dealing with spaces

  • Hello All,

    I am new to the SQL realm and at work I use SQL Studio.

    I have a question in regards to wildcards.

    I am searching distinctly for a string value in a column.

    I want to only look up patients by this specific string value.

    It is this (verbatim): ‘LifeCare Amb MH’

    the coding structure I use is:

    select top 5*

    from Integration.Encounter                     where [Facility] like ‘%LifeCare Amb MH%’

    table - Integration.Encounter

    column - Facility

    string value - LifeCare Amb MH

    SQL does not like that where statement line.

    I believe it’s because of the spacing of the words when trying to use a wildcard.

    How do I work with the spacing issue? It is a real string in a column. Just can’t seem how to get around the spacing issue.

    All the help is greatly appreciated.

    thank you!





    • This topic was modified 1 year, 4 months ago by  Ctalley13.
  • Are you searching for an exact match or just records that contain "LifeCare Amb MH"?

    Since you didn't provide any consumable data, it's hard(er) to figure out what the problem is. If you want an exact match, you'd use

    WHERE SomeColumn = 'LifeCare Amb MH’

    if you want all the records where SomeColumn starts with that, you'd use

    WHERE SomeColumn = 'LifeCare Amb MH%’

  • I apologize in advance, my wording in the original post was wrong.

    the table is - Integration.Encounter

    the column is - Facility

    specific string value I am trying to find in the facility column is: LifeCare Amb MH

    referring back to the original chunk of code,

    I used:

    select top 5*

    from integration.Encounter

    where Facility like ‘%LifeCare Amb MH%’

    I want to find in the dataset all the patients that have a string value of LifeCare Amb MH.

    however, I don’t know how to work around the spacing of the string when trying to use the wildcard to find all patients with that value.

    thank you

  • If you're trying to do an exact match, it's just:

    WHERE [ColumnName] = 'LifeCare Amb MH'

    Starts with and ends with is easy:

    WHERE [ColumnName] LIKE 'LifeCare Amb MH%'

    WHERE [ColumnName] LIKE '%LifeCare Amb MH'

    The fun starts where you have multiple spaces between each word. is that what's happening in your data?

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • Ctalley13 wrote:

    SQL does not like that where statement line.

    What specifically do you mean by that?  What error message did you get?

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who give you the shirt off *someone else's* back.

Viewing 7 posts - 1 through 7 (of 7 total)

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