these are my data:
and I want to have this result:
Please note that the values inserted into column "App", haven't got the same value or the same quantity, so once I could find 2 rows and another time 10 rows
these are my data:
and I want to have this result:
Please note that the values inserted into column "App", haven't got the same value or the same quantity, so once I could find 2 rows and another time 10 rows
You can use a temp table to store your app values, then concat them into a variable. Finally using T-SQL you can construct your dynamic pivot:
CREATE TABLE #VALS (VALS NVARCHAR(MAX))
INSERT INTO #VALS
SELECT DISTINCT APP
FROM [TABLE1]
DECLARE @SQL NVARCHAR(MAX)
DECLARE @VALS NVARCHAR(MAX)
SELECT @VALS = COALESCE(@VALS+', ','') + '[' + VALS + ']' FROM #VALS
SET @SQL = '
SELECT NAME, '+@VALS+'
FROM [TABLE1]
PIVOT (MAX([VERSION]) FOR APP IN ('+@VALS+')) PIV'
PRINT @SQL
EXEC (@SQL)