Change label series value in chart

SQL does not allow a subquery in AS. If you need variable column names in the SQL query, you would need to use dynamic SQL. One way to get variable column names without dynamic SQL:

  1. Add a custom property of type dataset to the chart and put the SQL binding without AS statements for PIR#_TEMP columns on it.
  2. Add another custom property dataset or string for column names with the appropriate SQL binding.
  3. Use scripting to create a dataset with the column names from #2 and add the data rows from #1 to it and then write this dataset to the chart’s dataset.

I suspect there may be a better way to accomplish this. EDIT: See PGriffith’s answer below for a simple way to do #3.