May 11, 2007 at 3:39 pm
This should be an easy one for all you Pros!
I'm trying to search for the actual percent sign in a field using a like statement. Normally, the query like would say:
where note like '%sample%'
I want to look for the actual % sign. I know you can't do:
where note like '%%%'
I was thinking about using the ASCII character 37, but don't know if this would work and if so, exactly how you write it:
where note like &CHAR#37
May 11, 2007 at 3:48 pm
Try
Like '%[%]%'
Brian
May 11, 2007 at 3:50 pm
This worked, thanks!
Now for my side question:
What if my field only had a Percent Sign in it?
='[%]' and =[%]
do not work.
May 11, 2007 at 3:51 pm
In the BOL, use the Index search, look up LIKE. Choose the option for the Transact SQL entry. Scroll down until you see Pattern Matching with the Escape Clause.
-SQLBill
May 11, 2007 at 3:54 pm
You only escape out the character if you are using LIKE.
='%'
Brian
May 11, 2007 at 3:59 pm
Thanks, again.
My field was a text field, so I couldn't use = '%'
Server: Msg 306, Level 16, State 1, Line 1
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
May 15, 2007 at 2:17 am
Try
LIKE '/%' ESCAPE '/'
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply