Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 merging two tables

Author  Topic 

raindear
Yak Posting Veteran

64 Posts

Posted - 2014-07-01 : 13:37:37
Hi

I have a table called Store Sales with the following columns

Date
Total Qty Sold
RRP
Total Value Sold
Branch No.
Barcodes
Unit Cost

Then I have another table called ESales that contains this

Inv Date
Our Ship Qty
Unit Price (RRP Inc VAT)
Line Total
Invoice
Order
Line
Brand
Part
Description
Our Order Qty
Unit Price (Exc VAT)
Discount %
Discount Amt (Inc VAT)
Discount Amount (Exc VAT)
Tax Category
Tax Exempt
Group
Sales Cat
Cust. ID
Title
Customer
Name
Tax ID
Rep. ID
Credit Memo
Unit Price
Amount
Category ID
Cust. Amount
Number01
ShortChar01
ShortChar02
Clubcard

There are matching fields but none with the same name. They are

Inv Date = Date
Our Ship Qty = Total Qty Sold
Unit Price (RRP Inc VAT) = RRP
Line Total = Total Value Sold

What I want to do in merge the values in StoreSales to ESales and create additional columns for the data that is not there, these are

Branch No
Barcodes
Unit Cost

Any ideas how to insert the matching values and create the three new ones?

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-07-01 : 19:00:04
You'll need to clarify things before anyone can really help but first...

1) "There are matching fields but none with the same name." - Who cares? There is nothing that says that the names have to be the same. If you want to join the two tables on Inv Date = Date then do it. A join condition is just a boolean expression that gets evaluated for every combination of rows and has to evaluate to True for the two rows to be joined. What that boolean expression is is up to you.

In simple English, how would you answer these questions:

2) How should the rows be joined? By date? Other?
3) For the "missing" columns, what would you like to see appear? Branch No = "ESales"?
4) How would you calculate Unit Cost?



Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy
Go to Top of Page

raindear
Yak Posting Veteran

64 Posts

Posted - 2014-07-02 : 04:27:53
It's ok I resolved it.
Go to Top of Page
   

- Advertisement -