May 18, 2021 at 12:48 am
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!
May 18, 2021 at 1:07 am
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%’
May 18, 2021 at 1:25 am
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
May 18, 2021 at 2:54 am
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?
May 18, 2021 at 5:02 am
This was removed by the editor as SPAM
May 18, 2021 at 7:37 am
This was removed by the editor as SPAM
May 18, 2021 at 8:07 am
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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply