Solved

Query question

Posted on 2013-02-06
8
255 Views
Last Modified: 2013-02-16
Hi Experts,
I have a query question.  I have two table, 1). FP_Child, this table has a CHDOCKET (has 9 digits - 00D012345), 2). FP_SUP , this table has a SUPDOCKET too but not all the CHDOCKET are 9 digits, it might 8 digits - 00D12345).  I want to do a query this use CHDOCKET in FP_Child join the SUPDOCKET in FP_SUP, but I know when I join both table, the CHDOCKET must be exactly match the SUPDOCKET, bu tin my sitution , is any way I can make the query works even the SUPDOCKET is missing a one number compare to the CHDOCKET?  The CHDOCKET is always 9 digitis.  How can I make the 00D012345 (FP_Child table) Join 00D12345 (FP_SUP Table) will show 00D012345 in the query.

Thanks
0
Comment
Question by:jodstrr2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38861498
>is any way I can make the query works even the SUPDOCKET is missing a one number compare to the CHDOCKET?

No.  Access SQL can't do a 'join these two values even if one character is off'.

Can you predict with certainty which number will be off?  If yes, maybe there is a work-around.
0
 

Author Comment

by:jodstrr2
ID: 38861705
Yes, some of the SUPDOCKET in FP_SUP table are missing the "0" after the letter,  some of them are 9 digitis include the "0" after the letter, some of them are 8 digitis which missing the "0" after the letter.  But the FP_Child table always contained 9 digitis.
0
 

Author Comment

by:jodstrr2
ID: 38864560
Here is my query, but it seems not working:
SELECT FP_Child.CHDOCKET, FP_SUP.SUPDOCKET, IIf(Left([SUPDOCKET],3) & Right([SPDOCKET],5),[FP_child]![CHDOCKET]) AS expr1
FROM FP_Child INNER JOIN FP_SUP ON FP_Child.CHDOCKET = FP_SUP.SUPDOCKET
WHERE (((FP_Child.CHDOCKET)="00D012345"));

The SUPDOCKET in FP_SUP table is 00D12345
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:jodstrr2
ID: 38865057
I created a sub query (below) then add this sub query to my main query, works.
SELECT FP_SUP.SUPDOCKET, IIf(Left([SUPDOCKET],3) & Right([SUPDOCKET],5),Left([SUPDOCKET],3) & "0" & Right([SUPDOCKET],5)) AS [New Docket]
FROM FP_SUP;
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38865284
Based on your first comment, it looks like there are multiple scenarios in play for missing characters in order to do a successful join.

What I'd recommend in this situation is to add a column to the FP_SUP table that holds the correctly-formatted nine characters, then write a series of UPDATE statements to translate the eight-character SUPDOCKET to it's nine-character counterpart.

Then join on those two.

Doing three or four different expressions in a join is likely not going to work well.

Hope this helps.
Jim
0
 

Author Comment

by:jodstrr2
ID: 38865367
Hi Jim, the FP_SUP table is a history table and we don't want to update the table, is any way I can use the LEN in the query?  like if the LEN of the SUPDOCKET in the FP_SUP table is 8 digits then add a "0", otherwise leave as 9 digits.
0
 

Accepted Solution

by:
jodstrr2 earned 0 total points
ID: 38877998
The correct query is:
SELECT FP_SUP.SUPDOCKET, IIf(Len([SUPDOCKET])=9,[SUPDOCKET],(Left([SUPDOCKET],3) & "0" & Right([SUPDOCKET],5))) AS NewDocket
FROM FP_SUP;
0
 

Author Closing Comment

by:jodstrr2
ID: 38896186
This works.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question