I currently have a table in SQL Server that looks something like this:
Machine | Serial | Date | Parameter | Value |
---|---|---|---|---|
Machine 1 | 12345 | 7/22/2021 | Param 1 | 789 |
Machine 1 | 12345 | 7/22/2021 | Param 2 | 456 |
Machine 1 | 67890 | 7/22/2021 | Param 1 | 123 |
Machine 1 | 67890 | 7/22/2021 | Param 2 | 456 |
Machine 1 | 34567 | 7/22/2021 | Param 1 | 789 |
Machine 1 | 34567 | 7/22/2021 | Param 3 | 123 |
I am attempting to create a view that transforms this table into something like this, where each row is defined by it's serial number and the view headers are defined dynamically by the parameters in the 'Parameter' column
Serial | Machine | Date | Param 1 | Param 2 | Param 3 |
---|---|---|---|---|---|
12345 | Machine 1 | 7/22/2021 | 789 | 456 | |
67890 | Machine 1 | 7/22/2021 | 123 | 456 | |
34567 | Machine 1 | 7/22/2021 | 789 | 123 |
The intention here is that the original table can contain any number of unique parameters and the resultant view will then group by serial number and populate each column with it's respective value based on the parameter it is assigned.
So far I've tried messing with dynamic SQL but have not been able to produce any results. I have done similar things in the past without a dynamic number of parameters in the parameter column. Is something like this even possible on the database side or does this kind of manipulation need to happen on the client side?