一時テーブル (@table) を EXEC sp_executesql @query に渡すにはどうすればよいですか?
set @query = 'SELECT GsName, ' + @cols + ' from
(
select GSName, [THour], NumOfTransactions
from @table
) x
pivot
(
max([NumOfTransactions])
for [THour] in (' + @cols + ')
) p '