I want to declare a table variable and fill it from the pivot with dynamic column to perform join statement.
DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(M