Mid UNPIVOT SQL & Databases

Write a query to unpivot columns into rows.

Short answer: Use UNPIVOT or CROSS APPLY (VALUES ...) to turn columns into attribute/value rows — handy for EAV-style reporting.

Sample solution

T-SQL
SELECT EmpId, Metric, Val
FROM EmployeesWide
CROSS APPLY (VALUES
    ('Salary', Salary),
    ('Bonus', Bonus),
    ('Allowance', Allowance)
) v(Metric, Val);
VALUES unpivot is often clearer than the UNPIVOT operator.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details