473,385 Members | 1,922 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,385 software developers and data experts.

Simple query with "like" not working >:(

Ok, I'm baffled...

I'm making a query in access 97 between 2 tables. There is a field in
both tables called "DWGNO".

OPENORD has a record with a DWGNO of "00000012345"
DIEDATA has a record with a DWGNO of "12345"

I'm not doing this with VBA right now. I'm doing it through the query
gui.

My query:
Both tables are in the upper section with no links between them.
I have selected 4 fields. Only 3 are told to display results.
The field that is not showing results is where the criteria is entered.
The field is called DieData.DWGNO and the criteria is Like "*" &
[openord]![dwgno]

This shows no query results.
Please help me

Aug 24 '06 #1
11 6359
If you open these tables in design view, what is the Data Type of the
fields? If they are Text, the text does not match because the string
"00000012345" is nothing like the string "12345"

If they are Number type fields, be aware that Like is a string operator, so
you are still performing a string match. Open the Immediate Window (Ctrl+G)
and enter these lines:
? "12345" Like "*" & "00000012345"
? "00000012345" Like "*" & "12345"
The first returns False, while the second returns True.
The example you gave is like the first one, which does not match.

The other think to keep in mind is that Nulls don't match with Like "*".

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bruce Lawrence" <BL*****@gmail.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
Ok, I'm baffled...

I'm making a query in access 97 between 2 tables. There is a field in
both tables called "DWGNO".

OPENORD has a record with a DWGNO of "00000012345"
DIEDATA has a record with a DWGNO of "12345"

I'm not doing this with VBA right now. I'm doing it through the query
gui.

My query:
Both tables are in the upper section with no links between them.
I have selected 4 fields. Only 3 are told to display results.
The field that is not showing results is where the criteria is entered.
The field is called DieData.DWGNO and the criteria is Like "*" &
[openord]![dwgno]

This shows no query results.
Please help me

Aug 24 '06 #2
I see.

Well, then I guess I need a VBA module to convert this to a regular
number or remove the leading zeros.

Unless you have some quick code to copy/paste here, I'll start hunting
for a resolution.

Thanks Allen

Aug 24 '06 #3
Make a backup copy of the mdb file (while it is NOT in use.)

Open the Relationships window (Tools menu), and remove any relationships
that use these fields.

Open the tables in design view, and change the Data Type to Number. Save.
Verify the numbers are still correct (sans the leading digits.)

Close the tables. Go back to the Relationships window again, and create the
relations with the Referential Integrity box checked.

They should now match correctly.

BTW, you can still display them with leading zeros if you wish, even after
converting them to numbers. Just set the Format property of the fields, to:
00000000000

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bruce Lawrence" <BL*****@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>I see.

Well, then I guess I need a VBA module to convert this to a regular
number or remove the leading zeros.

Unless you have some quick code to copy/paste here, I'll start hunting
for a resolution.

Thanks Allen

Aug 24 '06 #4
Theres a small snag with that. These aren't always going to be
numeric fields. We could have "00012345R1"

The problem is the lady who updated the records in the DieData table
left the 0's out of it. The openord records come out of our SAP system
and I import those automatically through import specs.

I'm going to need some type of function or whatever to take out the
preceding zeros and then compare the 2 fields.

I'm not having much luck with that part

Aug 24 '06 #5
Bri
Bruce Lawrence wrote:
Ok, I'm baffled...

I'm making a query in access 97 between 2 tables. There is a field in
both tables called "DWGNO".

OPENORD has a record with a DWGNO of "00000012345"
DIEDATA has a record with a DWGNO of "12345"

I'm not doing this with VBA right now. I'm doing it through the query
gui.

My query:
Both tables are in the upper section with no links between them.
I have selected 4 fields. Only 3 are told to display results.
The field that is not showing results is where the criteria is entered.
The field is called DieData.DWGNO and the criteria is Like "*" &
[openord]![dwgno]

This shows no query results.
Please help me
The problem is that you are putting the wildcard on the field WITH the
leading zeros. Try it the other way around:
openord!dwgno Like "*" & DIEDATA!dwgno

Another alternative is (assuming that these always are numbers):
CLng(openord!dwgno) = CLng(DIEDATA!dwgno)
or if they really will get into the nine or ten digit length:
CDec(openord!dwgno) = CDec(DIEDATA!dwgno)

The wildcard criteria and thes conversion criteria could be slow if
there are a lot of records since none of them will use indexes on the
dwgno fields. If these are truely numbers, then maybe you should store
them as numbers and indes them. Then you could format the number to add
in the leading zeros on output. This would be much faster and also more
efficient in storage.

--
Bri

Aug 24 '06 #6
Len() gives you the length of a string.
String() gives you a number of characters.

So you may be able to use an Update query to pad a field named F1 with
leading zeros so it is 11 characters long. The expression would be something
like this:
String(11-Len([F1]), "0") & [F1]

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bruce Lawrence" <BL*****@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Theres a small snag with that. These aren't always going to be
numeric fields. We could have "00012345R1"

The problem is the lady who updated the records in the DieData table
left the 0's out of it. The openord records come out of our SAP system
and I import those automatically through import specs.

I'm going to need some type of function or whatever to take out the
preceding zeros and then compare the 2 fields.

I'm not having much luck with that part

Aug 24 '06 #7
Sorry for dragging this out but I'm getting confused with which
solution I use or even search for.

They are text fields because of the alphanumeric values put into DWGNO.
DWGNO in the OpenOrd table is automatically filled in with an import.
DWGNO in DieData table is manually updated.

In my database, I ask the user for an order number. That order number
and the DWGNO is looked up in the OpenOrd table. I then take the DWGNO
and try to find it in the DieData table so I can get information from
that table as well.

The challenge is finding the DGWNO in DieData. DieData's is smaller
than OpenOrd's.

I have posted an image of my query online so you can see what I'm
doing.

http://www.c-o-g.com/img/qryprob.jpg

Aug 24 '06 #8
Bruce Lawrence wrote:
Ok, I'm baffled...

I'm making a query in access 97 between 2 tables. There is a field in
both tables called "DWGNO".

OPENORD has a record with a DWGNO of "00000012345"
DIEDATA has a record with a DWGNO of "12345"

I'm not doing this with VBA right now. I'm doing it through the query
gui.

My query:
Both tables are in the upper section with no links between them.
I have selected 4 fields. Only 3 are told to display results.
The field that is not showing results is where the criteria is entered.
The field is called DieData.DWGNO and the criteria is Like "*" &
[openord]![dwgno]

This shows no query results.
Please help me
?

Like "*" & trim(str([openord]![dwgno])) & "*"

--
Smartin
Aug 25 '06 #9
Bruce, let's identify the problem. It is that some fields have a fixed
number of leading zeros, and others are variable length, and therefore the
fields don't match?

Possible approaches:
A. Use an Update query to change the data so it does match. You can then
create a relationship between the table, and know that they will match for
sure. Use the information in the last post to pad everything with leading
zeros to (say) 11 characters in both tables. To make an update query, use
Update on the Query menu in query design. Then once the data matches, choose
Relationships on the Tools menu to create the relation, and check the box
for Referential Integrity. Problem permanently solved.

B. If the data is constantly being dumped and the bad data being imported
again, the permanent solution doesn't apply. You might solve it by repeading
the criteria under PRODORD on the next line again (the "Or" line in query
design), and adding this to the Or line under DWGNO from OPENORD:
Like "*" & [DieData].[Dwgno]
Now it doesn't matter which of the 2 tables has the leading zeros, the text
should match.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bruce Lawrence" <BL*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Sorry for dragging this out but I'm getting confused with which
solution I use or even search for.

They are text fields because of the alphanumeric values put into DWGNO.
DWGNO in the OpenOrd table is automatically filled in with an import.
DWGNO in DieData table is manually updated.

In my database, I ask the user for an order number. That order number
and the DWGNO is looked up in the OpenOrd table. I then take the DWGNO
and try to find it in the DieData table so I can get information from
that table as well.

The challenge is finding the DGWNO in DieData. DieData's is smaller
than OpenOrd's.

I have posted an image of my query online so you can see what I'm
doing.

http://www.c-o-g.com/img/qryprob.jpg

Aug 25 '06 #10
Bri

Bruce Lawrence wrote:
Sorry for dragging this out but I'm getting confused with which
solution I use or even search for.

They are text fields because of the alphanumeric values put into DWGNO.
DWGNO in the OpenOrd table is automatically filled in with an import.
DWGNO in DieData table is manually updated.

In my database, I ask the user for an order number. That order number
and the DWGNO is looked up in the OpenOrd table. I then take the DWGNO
and try to find it in the DieData table so I can get information from
that table as well.

The challenge is finding the DGWNO in DieData. DieData's is smaller
than OpenOrd's.

I have posted an image of my query online so you can see what I'm
doing.

http://www.c-o-g.com/img/qryprob.jpg
You have a decision to make. Either the field with the leading zeros
needs to lose those leading zeros or the other field needs to gain those
leading zeros. Otherwise you are trying to compare things that will
never be the same. I showed you a method for removing the leading zeros
by converting the field to a number, but it seems that this s an
alphanumeric field, so that won't work. Allen Browne showed you a
formula that will add in the leading zeros to the field without them.
His solution involves permanently changing the data in that field. The
problem with that is that if your data entry allows for the leading
zeros to not be entered, then the problem will recreate itself. Putting
the formula into the query will work, but it will be slow.

SELECT Openord.Prodord FROM Openord, DieData
WHERE openord!dwgno = String(11-Len(DIEDATA!dwgno), "0") & DIEDATA!dwgno

This does make the assumption that the fields are always 11 characters
long, but in your examples you've shown both 10 and 11 character fields.
I'm hoping that one of them was a typo.

--
Bri

Aug 25 '06 #11
Just an update....

The problem has been resolved. The issue was that the specs I was
provided for importing the SAP report .txt file into Access was wrong.
I was importing 5 columns to the left too many which was giving me
preceding 0's in the field.

The access import spec was adjusted and no records come in with 0's any
longer so I can do direct comparisons now.

My apologies for dragging you guys through the mud on something as
silly as this. I did learn though so some good came of it

Thanks again guys

Sep 12 '06 #12

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

Similar topics

2
by: QueenArenA.com | last post by:
I have a big problems because I have to query a database which contents contains some - ' - characters and obviously the query back with errors. An example is in www.queenarena.com/turbol.php ...
2
by: Tim Constantine | last post by:
I have a table "Subscriptions". Subscriptions contains the columns "ChannelID" & "MemberID". The "Channels" table contains a column called "Title" When someone is viewing a channel, I would...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
2
by: Big John | last post by:
in Access 2003 I am trying to get sql query to run using a field as input, but I want to input into the field a value that uses the "like" operator to find any value that starts with the value...
1
by: S. van Beek | last post by:
Dear reader, How can I filter a numeric field with Like as criteria in a query. To filter a numeric field with <10 as criteria this will com back with the result of those records for which...
1
by: Dean Slindee | last post by:
Can anyone point me to a code example or repository that would allow me to provide some "sounds like" comparison capability when doing a search for LastName? Thanks, Dean Slindee
3
by: Eric Layman | last post by:
Hi everyone. An image allows alt attribute. When mouse over images with alt attribute, a small yellow popup would appear besides the mouse cursor. How to replicate this behaviour using a table...
4
by: JPG4 | last post by:
I have tried just about everything that I can think of, so now I turn to you all for help! I have created a form (titled "OAG") with an unbound textbox titled "DOW". I also have a Query that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.