I have a table that looks like this:
| ID | Order | ... | Colour |
| 1 | A | ... | xxx |
| 2 | A | ... | xxx |
| 3 | A | ... | xxx |
| 4 | B | ... | xxx |
| 5 | B | ... | xxx |
| 6 | C | ... | xxx |
| 7 | A | ... | xxx |
| 8 | B | ... | xxx |
| 9 | B | ... | xxx |
| 10 | B | ... | xxx |
I need to assign each order its own color and return the value. Unfortunately I dont know what the order name will be so I can’t do a simple CASE statement.
My question is, what would be the best, most efficient way to do this so that the results look something like this:
| ID | Order | ... | Colour |
| 1 | A | ... | Red |
| 2 | A | ... | Red |
| 3 | A | ... | Red |
| 4 | B | ... | Blue |
| 5 | B | ... | Blue |
| 6 | C | ... | Green |
| 7 | A | ... | Red |
| 8 | B | ... | Blue |
| 9 | B | ... | Blue |
| 10 | B | ... | Blue |
Many thanks for your help, I’ve been puzzling over this all day!
Without answers to the questions posted in the comments, I can’t be sure this is what you want. But, here goes…
If your distinct Order values outnumber your Palette, it wraps around. You could also use NTILE instead of DENSE_RANK if you wanted to band orders into a set number of buckets to match your palette table’s count. The difference is in whether you want to cycle colors over values or group close values into a color.