convert columns to rows sql server -


this question has answer here:

these data:

enter image description here

and want have result:

enter image description here

please note values inserted column "app", haven't got same value or same quantity, once find 2 rows , time 10 rows

you can use temp table store app values, concat them variable. using t-sql can construct dynamic pivot:

create table #vals (vals nvarchar(max))  insert #vals select distinct app [table1]  declare @sql nvarchar(max) declare @vals nvarchar(max)  select @vals = coalesce(@vals+', ','') + '[' + vals + ']' #vals  set @sql = ' select name, '+@vals+' [table1] pivot (max([version]) app in ('+@vals+')) piv' print @sql exec (@sql) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -