There is no problem for me to pivot statistic columns in my query e.g Column 1 , Column 2 , Column 3.... and so on.
But i would like to do this dynamic instead.
My data looks like this:
i want to be able to EXECUTE a store procedure to get the output result: Exec sp_output 1 (from another window where '1' represents the PoolID (@AppPool)) to look like this:
This is my SP:
create PROCEDURE [dbo].[sp_test]
@Query as nvarchar(100) -- OUTPUT?,
@AppPool AS nvarchar(50)
AS
SELECT @Query = Attribute FROM [dbo].[Vy_UserAccess] WHERE PoolID = @AppPool
SELECT [Users],'+ @Query +' FROM
(SELECT [Pool],[Users],[RecNum],[Attribute],[Values] FROM [dbo].[Vy_UserAccess] ) AS T1
PIVOT (MAX([Values]) FOR [ATTRIBUTE] IN ('+ @Query +')) AS T2
Is this possible to achieve by just fine tuning my code or do i have to go on another direction?
You can do It in following:
QUERY
EXECUTION
QUERY WITH SAMPLE DATA
OUTPUT