Like function is returning exepected value

select is,title from table where title like'[New]' and id =111
Eventhough it has value [New]path it's returning no value

Table:
Id  title
111 [New]path
LVL 5
VIVEKANANDHAN_PERIASAMYAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EdgarPoeCommented:
Try using

select is,title from table where title like'[New]%' and id =111

or select is,title from table where title like'%[New]%' and id =111

http://msdn.microsoft.com/en-us/library/ms179859.aspx
0
VIVEKANANDHAN_PERIASAMYAuthor Commented:
select id,title from Change
where  title like'%[New]%'

It's returning something unexepected values.
0
EdgarPoeCommented:
Yes, I've checked it. Try this:

select is,title from table where title LIKE '%[ [ ]New]%'

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

VIVEKANANDHAN_PERIASAMYAuthor Commented:
Will like statement will not take special character?
0
Tony BarkdullCommented:
Try this

select id,title from Change
where id=111

Examine results. Are all id's = 111? If not, examine field type is a number or not. If not try id like '111'.

Then try

select id,title from Change
where  title like'[New]%' (providing all BEGIN with [New])

Examine results, then combine

select id,title from Change
where  title like'[New]%' and id=111
or
where  title like'[New]%' and id like'111'


0
EdgarPoeCommented:
Will like statement will not take special character?
What special character?  [ ] are wildcard characters so you need them to put in brackets to match them as literal characters.

Check source I've posted above:

% - Any string of zero or more characters.      WHERE title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title.

[ ] - Any single character within the specified range ([a-f]) or set ([abcdef]).


If you want to get rows where title only begin with [New], not [New] inside, use:

select is,title from table where title LIKE '[ [ ]New]%' and id =111
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VIVEKANANDHAN_PERIASAMYAuthor Commented:
I got below result.

select id,title from Change
where id=111
changeid      changetitle
111      [New] abc-1.0.0

select id,title from Change
where  title like'[New]%'

It displaying even not starting with the string [New]
changeid      changetitle
60      abc (ab-abc) Temp

0
VIVEKANANDHAN_PERIASAMYAuthor Commented:
EdgarPoe:
It works ,Thanks.
LIKE '[ [ ] New]%'
Here inside wildcard[]- before New]% what does it do?
it is something like [empty stringNew]%?
0
EdgarPoeCommented:
LIKE '[[]' means: LIKE any single character in [ ] brackets - so it is: LIKE [

If you use LIKE '[New]%' (without [[]) it means: LIKE any single character in [ ] brackets and any other characters (it is from % wildcard) - so it is:
LIKE N% or LIKE e% or w%

0
VIVEKANANDHAN_PERIASAMYAuthor Commented:
Thanks, I understood that.I like to know how does it's taking the value begining with [new]?
0
EdgarPoeCommented:
It's % wildcard:

like '%abc' gives anything before abc: abc, aaabc, sadaabc, etc.
like 'abc%' gives anything after abc: abc, abcd, abcdef, etc.
like '%abc%' gives anything what has abc inside: abc, aabc, abcde, aaabcde, etc.

In your example it is: LIKE '[[]New]%' which means: LIKE [New] and any other characters at end.

Is that clear?
0
VIVEKANANDHAN_PERIASAMYAuthor Commented:
EdgarPoe: i KNOW % IS THE WILDCard
I am confused at the inner square bracket[]
[[i didn't understand this inner Square bracket] New]%

Can you please explain this?
0
EdgarPoeCommented:
Ok. [ ] brackets works together as wildcard characters. But when you use [[] it means inner [ bracket is literal character so the New] bracket is also just literal.
] bracket is wildcard only with [ before it, without it it's just ].

That means LIKE '[New[]]%' should also work fine - now the ] bracket is set to be literal and first [ bracket doesn't work as wildcard without ]
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.