Everytime I use the pivot clause within SQL, I wonder why the IN
Statement has to be static and I need to write something like 'A', 'B'
.
SELECT *
FROM
(
SELECT key_1, column_name, value_1
FROM table_1
)
PIVOT
(
MAX(column_name)
FOR column_name in('A', 'B')
)
Is there a technical reason why it's not allowed to write something like
SELECT *
FROM
(
SELECT key_1, column_name, value_1
FROM table_1
)
PIVOT
(
MAX(column_name)
FOR column_name in(SELECT value_1 FROM table_2)
)
Because it would be obviously a lot more comfortable to write the IN
query dynamic.
Thanks for your answers!