I am wanting to look up data from one of my database tables based on a varchar stored in another table.
We have a table of Manufacturers (M) and a table of Parameters (P), and rather than having to have a parameter per Manufacturer (as there is a lot of crossover between 60% of them), we thought it would be cleaner to have parameters per manufacturer where required, and for the other ones just have a set of default parameters.
This means that I cannot store ManufacturerID in both tables and create a simple link, instead I need to link using the ManufacturerName.
So I need to know if it is possible to Link via ManufacturerName, and where there is no match look in the Parameters table (P) for Manufacturer 'Default'.
As part of the link, we are also including:
P.CategoryID = M.CategoryID AND (P.PriceFrom <= M.BasePrice AND P.PriceTo >= M.BasePrice)
Here is the data structures:
Manufacturers (M):
ManufacturerID, ManufacturerName, CategoryID, BasePrice
Parameters (P)
CategoryID, ManufacturerName, PriceFrom, PriceTo, Percentage
Here is some sample data:
Manufacturers (M):
ManufacturerID | ManufacturerName | CategoryID | BasePrice
3 | Apple | 1 | 150.00
3 | Apple | 9 | 99.99
10 | HTC | 1 | 50.00
15 | Nokia | 1 | 25.00
19 | Samsung | 1 | 80.00
Parameters (P):
CategoryID | ManufacturerName | PriceFrom | PriceTo | Percentage |
1 | Samsung | 0.00 | 99.99 | 50% |
1 | Apple | 0.00 | 99.99 | 55% |
1 | Apple | 100.00 | 149.99 | 45% |
9 | Apple | 0.00 | 99.99 | 65% |
1 | Default | 0.00 | 99.99 | 60% |
So we still need to just return 1 result in each link.
Any suggestions of guidance much appreciated.
Thanks in advance.