-1
SELECT *
FROM
(
    SELECT ParameterName,[VALUES]
    FROM @ValueHolder
) AS SourceTable PIVOT(
[VALUES] FOR ParameterName IN(SELECT * FROM @ValueHolder)) AS PivotTable;

Not working.

Uwe Keim
  • 38,279
  • 56
  • 171
  • 280
SamStha
  • 39
  • 3

1 Answers1

1

The Pivot inner query is incorrect

[VALUES] FOR ParameterName IN(SELECT * FROM @ValueHolder)) AS PivotTable;

As per MSDN definition

syntax should be

...
PIVOT
(
    <aggregation function>(<column being aggregated>)
FOR
[<column that contains the values that will become column headers>]
    IN ( [first pivoted column], [second pivoted column],
    ... [last pivoted column])
) AS <alias for the pivot table>
<optional ORDER BY clause>;

Here IN clause requires specified column names and will not accept SELECT * expression supported by IN in WHERE clause.

You should consider using dynamic PIVOT syntax. See an example here

DhruvJoshi
  • 16,585
  • 6
  • 37
  • 57
  • In my case, no. of column is not fixed. so how to pivot? – SamStha Jun 15 '18 at 09:19
  • @SamStha I suggest you post a new question after trying out dynamic pivot [http://crispycrappy.blogspot.com/2013/12/dynamic-sql-pivot.html] syntax. You'd need to tell more about `@valueholder` variable. – DhruvJoshi Jun 15 '18 at 09:32