I have a table with ~80k rows in the following format:
+--------+-----------+-------------------+---------------------+----------------------+-----------------+----------------+-----------------+
| SiteID | SubSiteID | DynamicPropertyID | DynamicPropertyName | DynamicPropertyValue | StaticProperty1 | StaticPropety2 | StaticProperty3 |
+--------+-----------+-------------------+---------------------+----------------------+-----------------+----------------+-----------------+
| 1 | 1 | 1 | Property1 | ABC | 1 | 1 | 1 |
| 1 | 1 | 2 | Property2 | XYZ | 1 | 1 | 1 |
| 1 | 1 | 3 | Property3 | DEF | 1 | 1 | 1 |
| 1 | 2 | 1 | Property1 | GHT | 1 | 1 | 1 |
| 1 | 2 | 2 | Property2 | XYZ | 1 | 1 | 1 |
| 1 | 2 | 3 | Property3 | WWF | 1 | 1 | 1 |
| 2 | 1 | 1 | Property1 | FHS | 1 | 1 | 1 |
| 2 | 1 | 2 | Property2 | HHS | 1 | 1 | 1 |
| 2 | 1 | 3 | Property3 | BSF | 1 | 1 | 1 |
| 2 | 2 | 1 | Property1 | QDD | 1 | 1 | 1 |
| 2 | 2 | 2 | Property2 | FFF | 1 | 1 | 1 |
| 2 | 2 | 3 | Property3 | YTR | 1 | 1 | 1 |
+--------+-----------+-------------------+---------------------+----------------------+-----------------+----------------+-----------------+
What I need to do, is create a view for this table that pivots the table into the following format:
+--------+-----------+-----------+-----------+-----------+-----------------+-----------------+-----------------+
| SiteID | SubSiteID | Property1 | Property2 | Property3 | StaticProperty1 | StaticProperty2 | StaticProperty3 |
+--------+-----------+-----------+-----------+-----------+-----------------+-----------------+-----------------+
The issue I am facing, is that we may be adding new 'dynamic properties' over time to the table, so the view needs to be able to dynamically change to add a new column if we add Property4
to each SiteID/SubsiteID combination, for example.
Any advice or help with this is greatly appreciated.