Wildcard SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to do wildcard searches on fields in a table regardless of what is
entered.

I have done this:

SELECT * FROM TF WHERE (NO_BLDG LIKE '%::Organisation::%' OR AD_LINE_1 LIKE
'%::Organisation::%' or AD_LINE_2 LIKE '%::Organisation::%' or AD_LINE_3
LIKE '%::Organisation::%' or AD_LINE_4 LIKE '%::Organisation::%' or
AD_POSTCODE LIKE '%::Organisation::%' or NM_CUSTOMER LIKE
'%::Organisation::%')

However, this is now working 100%.

Can someone help?

skc
 
What is this code doing that you don't like?

Or contrawise, what is it not doing that you wish it did?

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
*-----------------------------­-----------------------
|\----------------------------­-----------------------
|| Microsoft Windows SharePoint Services Inside Out
|| Microsoft Office FrontPage 2003 Inside Out
||----------------------------­-----------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/----------------------------­-----------------------
*-----------------------------­-----------------------
 
However, this is now working 100%.
Can someone help?

What percent would you like it to work? Perhaps we can mess it up just a
little.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
Sorry - what I mean't was that it is not working 100%.

E.g. if I type in Smith and get back 50 roads called Smith Street. There
maybe a building name called Bloggs. When I enter Bloggs, I would expect to
get Smith Street - but I don't get Smith Street.

Very odd. Any help now? Thanks.
 
This shouldn't make any difference, but try:

SELECT * FROM TF
WHERE (NO_BLDG LIKE '%::Organisation::%')
OR (AD_LINE_1 LIKE '%::Organisation::%')
OR (AD_LINE_2 LIKE '%::Organisation::%')
OR (AD_LINE_3 LIKE '%::Organisation::%')
OR (AD_LINE_4 LIKE '%::Organisation::%')
OR (AD_POSTCODE LIKE '%::Organisation::%')
OR (NM_CUSTOMER LIKE '%::Organisation::%')

Also, inspect your input values and data values *very* carefully for extra
spaces, apostrophes, percent signs, and so forth.

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Windows SharePoint Services Inside Out
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
The general problem w/ the LIKE structure using %::Organisation::% is it is looking for a match that has anything (something) before
and also after 'Organisation' (due to the % wildcard)

So you will not get a hit for any word that is the first or last word in the DB field
(since there is nothing before the first word or after the last word in that field)

If your record is 'Bloggs Building' there is no way for a match w/a wildcard on it using the LIKE and the wild card
(the field would need to be ' Bloggs Building ' to find Bloggs - that has something before and after Bloggs - a space)



--




| This shouldn't make any difference, but try:
|
| SELECT * FROM TF
| WHERE (NO_BLDG LIKE '%::Organisation::%')
| OR (AD_LINE_1 LIKE '%::Organisation::%')
| OR (AD_LINE_2 LIKE '%::Organisation::%')
| OR (AD_LINE_3 LIKE '%::Organisation::%')
| OR (AD_LINE_4 LIKE '%::Organisation::%')
| OR (AD_POSTCODE LIKE '%::Organisation::%')
| OR (NM_CUSTOMER LIKE '%::Organisation::%')
|
| Also, inspect your input values and data values *very* carefully for extra
| spaces, apostrophes, percent signs, and so forth.
|
| Jim Buyens
| Microsoft MVP
| http://www.interlacken.com
| Author of:
| *----------------------------------------------------
||\---------------------------------------------------
||| Microsoft Windows SharePoint Services Inside Out
||| Microsoft Office FrontPage 2003 Inside Out
|||---------------------------------------------------
||| Web Database Development Step by Step .NET Edition
||| Microsoft FrontPage Version 2002 Inside Out
||| Faster Smarter Beginning Programming
||| (All from Microsoft Press)
||/---------------------------------------------------
| *----------------------------------------------------
|
|
| "Skc" wrote:
|
| > Sorry - what I mean't was that it is not working 100%.
| >
| > E.g. if I type in Smith and get back 50 roads called Smith Street. There
| > maybe a building name called Bloggs. When I enter Bloggs, I would expect to
| > get Smith Street - but I don't get Smith Street.
| >
| > Very odd. Any help now? Thanks.
| >
| > "Jim Buyens" wrote:
| >
| > > What is this code doing that you don't like?
| > >
| > > Or contrawise, what is it not doing that you wish it did?
| > >
| > > Jim Buyens
| > > Microsoft MVP
| > > http://www.interlacken.com
| > > Author of:
| > > *-----------------------------­-----------------------
| > > |\----------------------------­-----------------------
| > > || Microsoft Windows SharePoint Services Inside Out
| > > || Microsoft Office FrontPage 2003 Inside Out
| > > ||----------------------------­-----------------------
| > > || Web Database Development Step by Step .NET Edition
| > > || Microsoft FrontPage Version 2002 Inside Out
| > > || Faster Smarter Beginning Programming
| > > || (All from Microsoft Press)
| > > |/----------------------------­-----------------------
| > > *-----------------------------­-----------------------
| > >
| > > "Skc" wrote:
| > >
| > > > I want to do wildcard searches on fields in a table regardless of what is
| > > > entered.
| > > >
| > > > I have done this:
| > > >
| > > > SELECT * FROM TF WHERE (NO_BLDG LIKE '%::Organisation::%' OR AD_LINE_1 LIKE
| > > > '%::Organisation::%' or AD_LINE_2 LIKE '%::Organisation::%' or AD_LINE_3
| > > > LIKE '%::Organisation::%' or AD_LINE_4 LIKE '%::Organisation::%' or
| > > > AD_POSTCODE LIKE '%::Organisation::%' or NM_CUSTOMER LIKE
| > > > '%::Organisation::%')
| > > >
| > > > However, this is now working 100%.
| > > >
| > > > Can someone help?
| > > >
| > > > skc
 
Hmm. I just tried this in Access, using a table that contains these three
values in a field named "place":

Bloggs Building
Building Bloggs
All Bloggs Buildings

The query:

SELECT * FROM places WHERE (((places.place) Like "*Bloggs*"));

returned all three records. Of course, when you go through ODBC or OLEDB, as
in the DRW, you have to change the quotes to apostrophes and the asterists to
percent signs.

As I understand it, the table contains:

123 Smith Street, Bloggs Building
89 Smith Street, Rupert Wu
1403 Smith Street, Julius Bloggs

and a search for smith finds all three records, a search for bloggs doesn't
find two.

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
*-----------------------------­-----------------------
|\----------------------------­-----------------------
|| Microsoft Windows SharePoint Services Inside Out
|| Microsoft Office FrontPage 2003 Inside Out
||----------------------------­-----------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/----------------------------­-----------------------
*-----------------------------­-----------------------
 
Sorry I didn't help. I was off yesterday. But I'm glad you got it sorted!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
Back
Top