Forum Discussion
benjamin_2024
Mar 01, 2025Copper Contributor
How do I unpivot so that the value column comes at the end?
hello all, I have learning the unpivot function, according to https://learn.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver16, the clause before the FOR ke...
olafhelper
Mar 04, 2025Bronze Contributor
By avoiding using the asteriks * in queries, additional you can use subqueries or CTE = common table expression.
With subquery it would be
SELECT SUB.PersonIdentifier, SUB.col1, SUB.col, SUB.value
FROM
(SELECT *
FROM ##temp1
UNPIVOT (value for col in (col2, col3, col4)) AS up
) AS SUB