I'm joining 2 tables.
ACCOUNTS
account_number region product
1234 100 AB
2345 0 AB
3456 300 CD
4567 0 CD
PRODUCTS
product region price
AB 100 $1.50
AB 0 $1.25
CD 0 $2.00
Each account record has a region and a product code Products are unique by product code and region.
However, the business logic says that if there is not a matching region in the PRODUCTS table, use the 0 region to get the price.
So I have to join by product and region to get the region specific pricing. In the example, accounts 1234, 2345 & 4567 find a matching record.
But I need to find a way for 3456 to join to the 0 region for product CD.
I suppose I could (ACCOUNTS left join PRODUCTS) and then update any null prices forcing region to 0 but how ugly is that?
Any ideas?
Also, I'm working with a vendor application so I can't change the schema or the data.
Database: MS SQLSERVER 2005