I have two table
Table A – Product information – color, size etc…(product_id, color, size…)
Table B – Rate information – rate might vary by color, size, state etc…
(rate_id, product_id, color, size, state, rate)
Not all products have rates that vary by color, size, state etc…This changes by product
If that is the case only attributes by which rates vary have a value in the rate table
e.g. if Product X rate does not vary by size or state but varies by color there will entries in the rate table with different color values but the size, state field will be null.
Is there a way in SQL to get the right rate value for a product
– I cannot match on all product attributes because there might not be a matching row
What I want is a query that gets the rate associated with Product X and will work with for other products whose rates may vary by different set of attributes.
Everything you want to know about the subject, and more: Dynamic Search Conditions in T-SQL.