473,404 Members | 2,114 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,404 software developers and data experts.

match full field from 1st table to first 9 characters in second table

I have been researching this one and I'm just not sure that I'm finding what I need or that I necessarily know what to call it. I'm thinking it is sort of a partial match but the things I'm trying are not returning anything.

I have an account numbers in two separate tables. I want to match the 9 digit acct number in the first table to the first 9 characters in the second table.

table 1.
123456789
456789123
789123456

table 2
123456789001
123456789002
123456789003
456789123003
234567891002
789987789006
456789123008

so I would want to return all the records from Table 2 except the one that starts 234.... and the one that starts 789....

I keep thinking this has to be fairly straight forward but I'm missing something.
thanks
Mar 14 '16 #1
4 1025
well the formatting didn't quite work

editing previous post
Mar 14 '16 #2
jforbes
1,107 Expert 1GB
You'll probably want to use the Like Operator

Maybe something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table2
  2. INNER JOIN Table1
  3. ON Table2.AcctNumber LIKE Table1.AcctNumber & '*'
This uses an Inner Join, to return the Table2 record only if a record exists on both sides of the join.
Mar 14 '16 #3
Narender Sagar
189 100+
You can also use =left([Field Name],9) function in a query and then in next query match this field with the Field in table 1.
Mar 14 '16 #4
MikeTheBike
639 Expert 512MB
Hi

Alternatively you could try
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table1 INNER JOIN Table2 
  2. ON Table1.AcctNumber = Left(Table2.AcctNumber,9)
  3. WHERE Left(Table1.AcctNumber,3) <> '234'
  4.  
??

MTB
Mar 14 '16 #5

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

Similar topics

4
by: Gervin | last post by:
I am using SQL Server 2000 and I want to be able to list out all the field names and their datatypes from a particular table. I found out that sp_help does that but unfortunately when using a...
7
by: Matt Kruse | last post by:
This is a typical layout, but I have specific requirements. I'm trying to figure out a) if it's possible to meet the requirements and b) if so, how. +---------------+ | header |...
0
by: kkrizl | last post by:
I'm having a very bizarre problem. I open up my table in datasheet view, and I click on edit, find. In the Find and Replace dialog box, I enter an address (123 main for example). If I set the...
2
by: J Sahoo | last post by:
Hi, I have a browse page where I am showing few fields from my SQL Server table. One of the field is Image type, all the fields are bound to a single table. I want to show the image from the...
3
by: John Dalberg | last post by:
I am using the Enterprise library and did an executedataset to retrieve results into a dataset. I noticed that the result went into the second table in the table collection of the dataset instead...
3
by: turtle | last post by:
I have Two tables (Table1 and Table2). Both tables have a common field called part number. Table 1 contains an extra field that i would like to update table 2 to match if the part number matches....
2
by: David - Australia | last post by:
G'day from Australia, I'm hoping some bright spark may be able to help me with this one. I'm sure that it can be done, I've just hit a wall with it. So I'm opening it up. I'm storing student...
2
by: amwi | last post by:
I have tried to solve this on my own for a long time now, so i really need some help here... I use Oracle 10.1 and SQL *plus 10.1. How do i update table a.fkid from table b.pkid with the...
2
by: biofly | last post by:
Hi Friends, I have two tables, second table has relation Table1: ---------- Id ---------- A01 A02
0
by: kkshansid | last post by:
I have to work with result database with three tables first, second and third year each consisting of around 150 fields I have to make combined report of all three years but to show subject field of...
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
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...
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
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
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.