I have a DB which has several tables that I need to be able to combine into one for reporting. I have a sample DB that I have posted. Here is the basics:
Tables:
Part
Customer
Tier
Region
CustomerDiscount
TierDiscount
RegionDiscount
Part table holds information about parts including cost/selling price, etc.
Customer table holds customer info. Each customer can be assigned a tier and region.
Discounts are offered for specific customers, tiers and regions and are assigned on a per-part basis. So for example in Tier A, Part 1 has $1 discount or whatever. Part 1 can also have a Region 2 discount of $2. Customer 1 can also have a $3 discount on that specific part. So altogether Customer 1's total discount would be $6.
What I am trying to do is get a query that will be able to show this.
The query is somewhat based on the Customer and their Tier/Region codes. For each customer I want to show every part, and the relevant discounts. For example:
Customer/Part/TierDiscount/RegionDiscount/CustomerDiscount
Cust1/Part 1/$1/$2/$3
Cust1/Part 2/$2/$1/$2
Cust2/Part 1/$2/$1/$2
Cust2/Part 2/$1/$2/$4
Some discounts do not apply to some Customers, say they are in a region with no discounts for Part 1, then the region discount for Part 1 should come up as $0. Some parts have no discounts at all, but they should still show, along with the selling price.
Since this information is coming from basically 5 different tables, I'm having issues combining everything and getting it to show correctly.
Tables:
Part
Customer
Tier
Region
CustomerDiscount
TierDiscount
RegionDiscount
Part table holds information about parts including cost/selling price, etc.
Customer table holds customer info. Each customer can be assigned a tier and region.
Discounts are offered for specific customers, tiers and regions and are assigned on a per-part basis. So for example in Tier A, Part 1 has $1 discount or whatever. Part 1 can also have a Region 2 discount of $2. Customer 1 can also have a $3 discount on that specific part. So altogether Customer 1's total discount would be $6.
What I am trying to do is get a query that will be able to show this.
The query is somewhat based on the Customer and their Tier/Region codes. For each customer I want to show every part, and the relevant discounts. For example:
Customer/Part/TierDiscount/RegionDiscount/CustomerDiscount
Cust1/Part 1/$1/$2/$3
Cust1/Part 2/$2/$1/$2
Cust2/Part 1/$2/$1/$2
Cust2/Part 2/$1/$2/$4
Some discounts do not apply to some Customers, say they are in a region with no discounts for Part 1, then the region discount for Part 1 should come up as $0. Some parts have no discounts at all, but they should still show, along with the selling price.
Since this information is coming from basically 5 different tables, I'm having issues combining everything and getting it to show correctly.