Skip to content
Advertisement

SQL Server 2016: how to get a single row view

I have been trying to word this correctly, but here’s my dbfiddle

Table:

Expected Output:

CustomerKey processdate Product_Mix Product_Mix_Expanded
101 2021-05-01 12,3,5 CCcount, CHKCount, SACount
102 2021-02-03 1,3,1 CCcount, CHKCount, SACount
103 2019-04-12 4,0,2 CCount, SACount

As you can see, I used STUFF, but not sure if that’s the right approach. I need the Product Mix showing the count and Product Mix Expanded in the worded format. Feel free to ask questions you need more inputs. Thank you in advance.

Advertisement

Answer

Based on your sample data and expected results does the following work for you?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement