Avatar of countrymeister
countrymeister
 asked on

Query syntax on conditional column joins

I have two tables ProductRatio and Products, here is some sample data
ProductRatio
Category     Group       ProductID  Ratio
NULL         NULL        NULL       0.12
Alpha                               0.15
Alpha        Group1                 0.22
Alpha        Group1      123        0.27

Products
Category     Group       ProductID  Ratio
Alpha        Group1     123        
Alpha        Group2
Generic      Group1

I need to update the Products table Ratio column such that
If there is an exact match between Category, Group, and ProductID from the ProductRatio table then use that value.
If one does not exist use the Category and Group value.
If that does not exist just use the Category value,
If that is not there than default to the NULL value ,which in this case is 0.12

Based on this hierachy the values updated for ratio column in the Products table would be
Products
Category     Group       ProductID  Ratio
Alpha        Group1     123         0.27
Alpha        Group2                 0.15
Generic      Group1                 0.12
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
SOLUTION
John_Vidmar

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61