Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

LIKE operator Expand / Collapse
Author
Message
Posted Tuesday, August 12, 2008 11:28 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, June 25, 2014 9:48 AM
Points: 52, Visits: 275
Comments posted to this topic are about the item LIKE operator

Susantha
Post #551602
Posted Wednesday, August 13, 2008 2:14 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 4:53 AM
Points: 2,366, Visits: 1,844
for a second i thought .... nice question

"Keep Trying"
Post #551665
Posted Wednesday, August 13, 2008 4:21 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-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...

Post #551728
Posted Wednesday, August 13, 2008 4:26 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:59 AM
Points: 280, Visits: 374
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!
Post #551729
Posted Wednesday, August 13, 2008 6:58 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, June 26, 2014 6:11 AM
Points: 1,330, Visits: 815
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.
Post #551843
Posted Wednesday, August 13, 2008 7:33 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, June 4, 2009 5:29 AM
Points: 49, Visits: 12
It was good question. I create confusion for underscore. I just like logical
Post #551879
Posted Wednesday, August 13, 2008 8:08 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #551917
Posted Wednesday, August 13, 2008 10:33 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 4,011, Visits: 6,082
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
Post #552085
Posted Wednesday, August 13, 2008 11:32 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:36 PM
Points: 5,303, Visits: 1,378
Good Question ....:)


Post #552138
Posted Wednesday, August 13, 2008 11:08 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 5, 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_]%'
Post #552412
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse