|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 8:47 AM
Points: 304,
Visits: 552
|
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, January 02, 2013 12:15 PM
Points: 1,443,
Visits: 711
|
|
| Clever question, not sure why/how I'd ever use the concept though. Good trivia?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:58 AM
Points: 2,570,
Visits: 1,530
|
|
| I am guessing you would use it if you had some sort of program code or oddly formatted text inserted into a table and each string started with either [] or [!] or something else and you wanted to return just those strings containing []? Possibly would be used in a find and replace scenario?
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: 2 days ago @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 12:52 PM
Points: 2,548,
Visits: 17,348
|
|
I think this question is valuable beyond just the trivia for several reasons: 1. Be careful when searching for brackets using like - they are a special character just like the percent and underscore (I had forgotten about this) 2. Remember that you can specify an escape character to search for one of the wildcard characters 3. If you do have some of the wildcard characters in your data, test carefully to make sure you can use LIKE like you want to (I would have thought that 2 would have shown up).
Chad
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 12:40 PM
Points: 193,
Visits: 210
|
|
Which is the exact meaning of ESCAPE? I thought it was to escape a wildcard that we would like to search. But the item didn't have any exclamation in the table, but even though the SQL returned the number 1.
Can someone explain why?
________________ DBA Cabuloso Lucas Benevides
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
Mark Horninger (8/26/2009) Clever question, not sure why/how I'd ever use the concept though. Good trivia?
Exactly. Good Trivia. But never came across a procedure which uses it, neither I ever wrote any script using escape.
SQL DBA.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
Jesse McLain When I was researching this, I was quite surprised to see #3 appear in the output.
I'm not. When you need to search for strings that include characters such as % or [, you have to escape them, and there are two ways to do that: by using the ESCAPE clause (but that requires you to be 100% positive that the chosenn escape character is never included in the search string), or by enclosing the special character in a [] pair. We all know that [abc] matches one character that can be either a, b, or c. So likewise, [a] matches one character that can be only a, and [[] or [%] match one character that can be only [ or %.
I missed my point by messing up the second pattern. When looking at the tail end of the pattern, I saw []] and parsed this as []] (the boldface indicates how I matched up closig and ending brackets - like how most typical humans would do it), instead of []] (what the computer apparently does). So the entire pattern string becomes (again, with matching begin and end brackets in bold) [[][]], translating to a single character which has to be [, followed by a single character which may not be any character at all (!), and then a single ] character.
Oh well, missed a point on a question designed to test something I knew, but learned an interesting thing - humans are still too smart for computers!
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
Mark Horninger (8/26/2009) Clever question, not sure why/how I'd ever use the concept though. Good trivia?
If you ever need to search a database of newsgroup messages, you'll be delighted to know how to properly search for messages that are marked "off topic" by using the common [OT] prefix in the message title.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
DBA Cabuloso (8/26/2009) Which is the exact meaning of ESCAPE? I thought it was to escape a wildcard that we would like to search. But the item didn't have any exclamation in the table, but even though the SQL returned the number 1.
Can someone explain why?
Books Online, perhaps?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|