|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, August 08, 2012 1:53 AM
Points: 52,
Visits: 255
|
|
Comments posted to this topic are about the item LIKE operator
Susantha
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
for a second i thought .... nice question
"Keep Trying"
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, March 21, 2011 8:57 AM
Points: 418,
Visits: 61
|
|
This one was quite simple (even for a n00b like myself :D) But a good try anyways...
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 2:35 AM
Points: 276,
Visits: 328
|
|
Nice one. To be honest: what I expected wasn't the right answer ;) But after testing it I knew what was :)
Thanks for the lesson in wildcard characters!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, February 04, 2013 10:00 AM
Points: 1,329,
Visits: 803
|
|
| Tricky, tricky! Good question though. I fell into the trap probably because I haven't had enough coffee yet this morning. I saw the % signs and just completely forgot about the _ as a wildcard.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, June 04, 2009 5:29 AM
Points: 49,
Visits: 12
|
|
| It was good question. I create confusion for underscore. I just like logical
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
You can also escape the wildcard characters with square-brackets.
where col like '[_]'
or
where col like '[%]'
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 1:52 PM
Points: 3,790,
Visits: 5,548
|
|
Good question, and a learning experience for me
I missed it too, not realizing that the underscore wouldn't catch 'C_us'. The lesson learned is that underscore as a wildcard means that there MUST be some character, but % will accept the absence of a character. Proved this out by modifying your question a touch.
create table #Like_Test( Col1 varchar(5) ) go insert #Like_Test values('_Cu') insert #Like_Test values('_Cus') insert #Like_Test values('Cus_') insert #Like_Test values('C_us') insert #Like_Test values('Cus') insert #Like_Test values('Cu_s')
select * from #Like_Test where Col1 Like '%Cu_%'
select * from #Like_Test where Col1 Like '%Cu%'
select * from #Like_Test where Col1 Like '%C%u%'
drop table #like_test
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller Stop, children, what's that sound? -- Stephen Stills
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 1:35 AM
Points: 4,789,
Visits: 1,336
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, October 05, 2012 3:23 AM
Points: 79,
Visits: 232
|
|
create table #Like_Test( Col1 varchar(5) ) insert #Like_Test values('_Cus') insert #Like_Test values('Cus_') insert #Like_Test values('C_us') insert #Like_Test values('Cus') insert #Like_Test values('Cu_s') select * from #Like_Test where Col1 Like '%Cu_%'
How can we really get the row with value as "Cu_" then? (I mean the last record in the above table)
Something like this doesnt works.. select * from #Like_Test where Col1 Like '%[Cu_]%'
|
|
|
|