I have two tables that can be seen in the accompanying image.
Table A contains Department , Month, and Average .
Table B contains Month , Year , RangeStart , RangeEnd, and Color .
If you look at the screenshot of Table B, you will see that for each month you have the values ββ"Green", "Yellow", "Orange" and "Red". You also have a range.
What I need.........
I need a new column in table A named Color. In this column, I need either green, yellow, orange, or red. The deciding factor for which the color is assigned to the month is the Medium column.
For example:
DepartmentA for May. The average value is 0.96 After referring to table B, I see that line 8, 0.75+ will be the range into which it fits. Therefore, the red color is the color that I want to place in table A, next to the average value of Mays.
I left the RangeEnd for the maximum range per month as NULL, since it is basically 75+ , something more than 0.75 here.
Can someone point me in the right direction, which is not too time consuming.

sql sql-server tsql sql-server-2008
Jsonstatham
source share