473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Like '' & '' & ''

Having this description column in a table

"Cookies, peanut butter sandwich, regular"
When using this WHERE clause:

WHERE (((Food_Data.Description) Like "*Butter*" & "*Peanut*"));

I dont get any results, however when using it this way round

WHERE (((Food_Data.Description) Like "*Peanut*" & "*Butter*"));

I get the row as expected.

I assume that the query looks for them in order.

Is there a way i can get around this and make the query search for both
keywords no matter which order i ype them in.

Thanks
Dave

Jul 20 '05 #1
3 15575
[posted and mailed]

SkunkDave (da***********@totalise.co.uk) writes:
Having this description column in a table

"Cookies, peanut butter sandwich, regular"
When using this WHERE clause:

WHERE (((Food_Data.Description) Like "*Butter*" & "*Peanut*"));

I dont get any results, however when using it this way round

WHERE (((Food_Data.Description) Like "*Peanut*" & "*Butter*"));

I get the row as expected.

I assume that the query looks for them in order.


The query looks for a string that matches the pattern "*Peanut**Butter*",
so obviously it's not going to match "Butter Peanut".

As suggested by Harald Albrech this works:

WHERE (Food_Data.Description Like "*Butter*" or
Food_Data..Description Like "*Peanut*");

Note that the newsgroup you posted is devoted to MS SQL Server, and
the syntax you posted is not legal in SQL Server, but it looks that
it could be Access. Access has its own newsgroup, I believe the name is
comp.databases.ms-access. You may want to post there next time you
have a problem.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Erland Sommarskog wrote:
[posted and mailed]

SkunkDave (da***********@totalise.co.uk) writes:
Having this description column in a table

"Cookies, peanut butter sandwich, regular"
When using this WHERE clause:

WHERE (((Food_Data.Description) Like "*Butter*" & "*Peanut*"));

I dont get any results, however when using it this way round

WHERE (((Food_Data.Description) Like "*Peanut*" & "*Butter*"));

I get the row as expected.

I assume that the query looks for them in order.

The query looks for a string that matches the pattern "*Peanut**Butter*",
so obviously it's not going to match "Butter Peanut".

As suggested by Harald Albrech this works:

WHERE (Food_Data.Description Like "*Butter*" or
Food_Data..Description Like "*Peanut*");

Note that the newsgroup you posted is devoted to MS SQL Server, and
the syntax you posted is not legal in SQL Server, but it looks that
it could be Access. Access has its own newsgroup, I believe the name is
comp.databases.ms-access. You may want to post there next time you
have a problem.

Ive used the query suggested except ive used the word 'and' instead of
'or'. Works fine.

Yes the query is MS Access. I didnt see the Access newsgroup. I would
have posted it there if i did.

Out of curiousity, what would be the syntax for SQL Server?

Cheers

Jul 20 '05 #3
SkunkDave (da***********@totalise.co.uk) writes:
Out of curiousity, what would be the syntax for SQL Server?


WHERE (Food_Data.Description Like '%Butter%' or
Food_Data.Description Like '%Peanut%');

OR or AND depends on the desired result when only one string is included.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Collin VanDyck | last post by:
I have a basic understanding of this, so forgive me if I am overly simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric character...
1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
6
by: Rich Wallace | last post by:
All, I receive an xml doc with an element which contains a &amp; in the data. I am attempting to insert the data into a SQL Server database and I want to convert the &amp; to a "&" character before I...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
3
by: gg | last post by:
I specify the Url element as <xsd:element name="Url"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="512"/> <xsd:pattern value="http://+"/> </xsd:restriction>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.