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

Match first 3 characters of a field from two different tables

Hi,

I have two different tables with forenames, surnames and DOB. I have done a straight forward match but wanted to see a match where Surname and DOB Matched exactly but match the forename from the first 3 characters (some are spelt slightly differently)

How would I go about this?

Thanks,
May 8 '17 #1

✓ answered by NeoPa

Hi Sam.

I've changed your posts #4 & #8 to show the SQL in a tidy format and you can easily see the problem. Tidiness and formatting are not simply nice to have pretty features. Without them you will easily miss obvious errors. How much time could have been saved?

Let us know if you are still having problems with your SQL once the obvious typo has been sorted out. If so, we'd prefer properly formatted and displayed SQL to work with.

It's easy to see such mistakes as wasting our time, but frankly, until you understand the importance of these things, how would you know? So, no worries about past errors. Just see how it goes forward from here.

BTW that tip is for general work and isn't restricted to when you post your questions in here.

Good luck.

NB. Mike is an experienced Access expert so when he gives advice, such as generally avoiding embedded spaces in table ( or other object) names, it's worth paying attention. Most here would give the same advice.

11 1129
MikeTheBike
639 Expert 512MB
Hi

Without seeing you query it is a bit difficult to suggest a definitive answer, but I imagine somewhere you will need something like this
Expand|Select|Wrap|Line Numbers
  1. WHERE Left(tblOne.Forename,3) = Left(tblTwo.Forename,3) AND tblOne.Surname = tblTwo.Surname AND tblOne.DOB = tblTwo.DOB
??

HTH


MTB
May 8 '17 #2
NeoPa
32,556 Expert Mod 16PB
I would suggest something on similar lines :
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblOne].*
  2.      , [tblTwo].*
  3. FROM   [tblOne]
  4.        INNER JOIN
  5.        [tblTwo]
  6.   ON   [tblOne].[Surname]=[tblTwo].[Surname]
  7.  AND   [tblOne].[DoB]=[tblTwo].[DoB]
  8. WHERE  (Left([tblOne].[Forename],3)=Left([tblTwo].[Forename],3))
May 8 '17 #3
Expand|Select|Wrap|Line Numbers
  1. SELECT [Missing UPNs].*
  2.      , [PupilOnRoll]
  3.      , *
  4. FROM   [Missing UPNs]
  5.        INNER JOIN
  6.        [PupilOnRoll]
  7.   ON   [Missing UPNs].[Surname]=[PupilOnRoll].[Surname]
  8.  AND   [Missing UPNs].[DateofBirth]=[PupilOnRoll].[DoB]
  9. WHERE  (Left([MissingUPNs].[Forename],3)=Left([PupilOnRoll],3))
I gave this a go but it's asking me to enter a parameter. I just need it to list all those that match. I'm not searching for ones in particular i.e. all that start with ste

Thanks,
Sam
May 9 '17 #4
MikeTheBike
639 Expert 512MB
Hi

You do no say which parameter is requested, but I thing this
Expand|Select|Wrap|Line Numbers
  1. Left([PupilOnRoll],3)
should be like this
Expand|Select|Wrap|Line Numbers
  1. Left([PupilOnRoll].[Forename],3)
??

MTB
May 9 '17 #5
Syntax error in query expression '(Left([MissingUPNs].[Forename],3)=Left([PupilOnRoll].[Forename],3);'

Just got this returned..
May 9 '17 #6
MikeTheBike
639 Expert 512MB
Without seeing the full query difficult to be sure, but you may be missing a final closing bracket, ie
Expand|Select|Wrap|Line Numbers
  1.  WHERE (Left([MissingUPNs].[Forename],3)=Left([PupilOnRoll].[Forename],3))
??

MTB
May 9 '17 #7
Expand|Select|Wrap|Line Numbers
  1. SELECT [Missing UPNs].*
  2.      , [PupilOnRoll]
  3.      , *
  4. FROM   [Missing UPNs]
  5.        INNER JOIN
  6.        [PupilOnRoll]
  7.   ON   [Missing UPNs].[Surname]=[PupilOnRoll].[Surname]
  8.  AND   [Missing UPNs].[DateofBirth]=[PupilOnRoll].[DoB]
  9. WHERE  (Left([MissingUPNs].[Forename],3)=Left([PupilOnRoll].[Forename],3));
This is the full query, I put in the extra bracket. Upon pressing run it prompted for parameters
May 9 '17 #8
MikeTheBike
639 Expert 512MB
AS I said before you do not say which parameter it request, but I think you have missed the space from the table name.
This
Expand|Select|Wrap|Line Numbers
  1. WHERE (Left([MissingUPNs].[Forename],3)=Left([PupilOnRoll].[Forename],3))
should be this
Expand|Select|Wrap|Line Numbers
  1. WHERE (Left([Missing UPNs].[Forename],3)=Left([PupilOnRoll].[Forename],3))
??

It is not considered good practice to have spaces in table or field names!

MTB
May 9 '17 #9
It's not my Table i'm just having to make do with what i've been given unfortunately. At present when i press run it's asking for a parameter for the following
  • Missing UPNs
  • PupilOnRoll
  • Missing UPNs.DateofBirth

Thanks in advance
May 9 '17 #10
MikeTheBike
639 Expert 512MB
If anything inside square brackets is not recognised then you will be asked to provide a value manually.

However this can get confusing if there are other syntax errors. For instance in your early post I have just noticed this
[PupilOnRoll],*
has a comma when a period is required.

If that does not progress it any, then I suggest you (temporarily) simplify the whole thing to and just include the field/tables it does not recognise in the SELECT statement (without the WHERE clause).

The other thing we do not know is how/where this query is being used, which may or may not have a bearing on it!


MTB
May 9 '17 #11
NeoPa
32,556 Expert Mod 16PB
Hi Sam.

I've changed your posts #4 & #8 to show the SQL in a tidy format and you can easily see the problem. Tidiness and formatting are not simply nice to have pretty features. Without them you will easily miss obvious errors. How much time could have been saved?

Let us know if you are still having problems with your SQL once the obvious typo has been sorted out. If so, we'd prefer properly formatted and displayed SQL to work with.

It's easy to see such mistakes as wasting our time, but frankly, until you understand the importance of these things, how would you know? So, no worries about past errors. Just see how it goes forward from here.

BTW that tip is for general work and isn't restricted to when you post your questions in here.

Good luck.

NB. Mike is an experienced Access expert so when he gives advice, such as generally avoiding embedded spaces in table ( or other object) names, it's worth paying attention. Most here would give the same advice.
May 9 '17 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: LRW | last post by:
I have a SQL string with a couple of JOINs that works perfectly in command prompt. I get results for all the fields selected just fine. But when I put it into a PHP page, I can't make variables(?)...
7
by: Paolo | last post by:
I know I should not be doing this, but I find it very useful. I have a database in Access which stores data for a small company. Sometimes we need to add similar information to different tables....
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
1
by: Laser Lu | last post by:
Hi, all, I'm now writing a program to compress JavaScript code. One puzzle is how to write a regular expression to find out and remove all the redundent blank spaces. However, those blank spaces...
20
by: Dennis Gearon | last post by:
I am working on a design where a location for something can have: Fully qualified address with even building names, room numbers, and booth numbers. **-OR-** GPS location **-OR-** Both ...
0
by: apgoh | last post by:
Our system is on AIX5.3 ML5, DB2 v8.2 FP11, and we are running C applications. There are 2 scheduled cronjobs, which are actually triggering the same binary, but passing in different parameter....
2
by: coolminded | last post by:
hi all, can we write a trigger in such a way that same trigger is fired when any query executes for two different tables. i mean to say, i have two tables tbla, tblb. right now i have written one...
21
by: Yoni Hasid | last post by:
Hello, I am trying to match tables into a query based on 5 first characters in one field. I used expression: =left(), 5) however it does not return matched entries as I needed. Basically, I need to...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.