March 4, 2009 at 12:43 am
Hi,
I just faced this weird issue while checking something in a
SP code. To simplify it I have replicated the problem below.
Why should the value 'LeftPanelSelect' be selected as part of the select stmt below? Am I missing something?
declare @tbl table(name varchar(30))
insert into @tbl(name) values ('l_ChildPeopleSelect')
insert into @tbl(name) values ('l_ChildSitesSelect')
insert into @tbl(name) values ('LeftPanelSelect')
insert into @tbl(name) values ('l_CompanyDetailsGetByName')
insert into @tbl(name) values ('l_CompanyDetailsGetByName')
insert into @tbl(name) values ('l_CompanyEventsGet')
select * from @tbl where name like 'l_%'
March 4, 2009 at 12:58 am
this is because _ is a wildchard character for single character
-Vikas Bindra
March 4, 2009 at 1:27 am
hi,
refer the topics
http://www.sqlservercentral.com/Forums/Topic551602-1325-2.aspx#bm567224
(Home » Article Discussions » Article Discussions by Author » Discuss content posted by Susantha Bathige » LIKE operator)
ARUN SAS
March 5, 2009 at 12:09 pm
To search for an underscore or percent sign (_ or %), specify and use an escape character. With a tilde escape, your query would be:
select * from @tbl where name like 'l~_%' ESCAPE '~'
March 5, 2009 at 12:15 pm
Or the classic style
DECLARE @t TABLE (txt VARCHAR(100))
INSERT INTO @t VALUES ('abc')
INSERT INTO @t VALUES ('a_bc')
SELECT * FROM @t WHERE txt LIKE 'a[_]%'
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply