I have an sql-server 2012
table that looks like this:
lvl | keywords
-----|------------
A | null
A1 | null
A1.1 | red, green
A1.2 | blue
A1.3 | orange, yellow
A2 | null
A2.1 | brown
A2.2 | black, purple
B | null
B1 | null
B1.1 | pink
B1.2 | velvet, orange
B2 | null
B2.1 | cyan
B2.2 | purple, white
etc.
I need a view that rolls up the keywords to the higher level. So top level A must have all the keywords from the underlying records where column lvl starts with A. Level A1 should have all the keywords from the records where column lvl starts with A1, etc. So the output of this view should be as follows:
lvl | keywords
-----|------------
A | red, green, blue, orange, yellow, brown, black, purple
A1 | red, green, blue, orange, yellow
A1.1 | red, green
A1.2 | blue
A1.3 | orange, yellow
A2 | brown, black, purple
A2.1 | brown
A2.2 | black, purple
B | pink, velvet, orange, cyan, purple, white
B1 | pink, velvet, orange
B1.1 | pink
B1.2 | velvet, orange
B2 | cyan, purple, white
B2.1 | cyan
B2.2 | purple, white
etc.
How to do that in T-SQL
? (sql-server 2012)