November 20, 2009 at 9:51 am
ronmoses (11/20/2009)
I got tripped up on the fact that the string didn't end with %. So I answered the question for 'Jo[^n]%' instead of 'Jo[^n]'. Oops.
Add me to this list. Read the question and answered too quickly. Missed the fact the % wasn't listed. :blink:
David
November 20, 2009 at 9:55 am
The answer, based on LIKE, is that you are looking for 3 character matches without the %.
So you have possible:
John
Jonathan
Jon
Joe
Jack
Of these, the 3 character ones are:
Jon
Joe
Of those, the pattern "JO[^n]" is matched only by Joe. Jon has an "n" in the third position and the caret (^) means do not match.
If we had added the % at the end, "JO[^n]%", then "John" would have matched as well. "Jonathan would not have matched with an "n" in the third position.
November 20, 2009 at 12:00 pm
Thank You.:-)
November 20, 2009 at 1:52 pm
Nice explanation. Thanks
Steve Jones - Editor (11/20/2009)
The answer, based on LIKE, is that you are looking for 3 character matches without the %.So you have possible:
John
Jonathan
Jon
Joe
Jack
Of these, the 3 character ones are:
Jon
Joe
Of those, the pattern "JO[^n]" is matched only by Joe. Jon has an "n" in the third position and the caret (^) means do not match.
If we had added the % at the end, "JO[^n]%", then "John" would have matched as well. "Jonathan would not have matched with an "n" in the third position.
November 23, 2009 at 4:14 am
I'm pretty sure the '^' character is a caret, not a carot 🙂
January 7, 2010 at 11:57 pm
Try this
select * from @table where [name] like 'Jo_'
January 25, 2010 at 6:42 pm
Steve Jones - Editor (11/20/2009)
The answer, based on LIKE, is that you are looking for 3 character matches without the %.So you have possible:
John
Jonathan
Jon
Joe
Jack
Of these, the 3 character ones are:
Jon
Joe
Of those, the pattern "JO[^n]" is matched only by Joe. Jon has an "n" in the third position and the caret (^) means do not match.
If we had added the % at the end, "JO[^n]%", then "John" would have matched as well. "Jonathan would not have matched with an "n" in the third position.
Wouldn't it have been nice if the answer's explanation had given this detail, or at the very least made the point that [^n] matches only a single character? The imaginary "%" on the end of the pattern mentioned bin a couple of comments describes exactly where I went wrong, don't know why because I should be on top of this given how much I've used it) but the explanations should surely try a bit harder to educate.
Tom
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply