Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine The Data of Two Rows

Status
Not open for further replies.

dwg23

Technical User
Oct 21, 2002
151
US
Hello,
I have two different tables that I need to pull information from.
Table One has rows like this.

CustomerNumber CustomerShipTo
123 456

The only field in table two that id close to matching is called ParentReferance which has the CustomerNumber and the CustomerShipTo from Table One combined to look like this:

ParentReferance
123 456

My question is how do I write the query to link the two tables.

Thanks
dwg23
 
Code:
SELECT <the fields you want>
  FROM TableOne
    JOIN TableTwo 
      ON TableOne.CustomerNumber + TableOne.CustomerShipTo = TableTwo.ParentReference

Tamar
 
The only thing that might cause you issues is the space or spaces between the values entered into ParentReference.

For example:
CustomerNumber CustomerShipTo
123 456
^ 1 space

is not the same as

ParentReferance
123 456
^^ 2 spaces

If you know the value in ParentReferance always uses one space, you should be good to go. If not, you'll have to do something to resolve that issue; such as using REPLACE to make it one space.

Also, Tamar's suggestion of the JOIN might not work as expected....it may concatenate the two values together without a space and then it won't match ParentReferance. If so, you'll need to change the ON to add a space between the two values.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
-SQLBill,
Thank you and I will keep this in mind for the future. I also thought put it together without the space but it worked like a champ!

Thank You Tamar also!

dwg23
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top