How to flatten a table using SQL Server? -
i'm using sql server 2012. project want flatten table, need help. table.
| applicationname | name | value | createdon | contoso | description | example website | 04-04-2014 | contoso | description | nothing | 02-04-2014 | contoso | keywords | contoso, about, company | 04-04-2014 | contoso | keywords | contoso, company | 02-04-2014
i want last modification record name application name. result want.
| applicationname | description | keywords | contoso | example website | contoso, about, company
i don't temp tables. knows how this?
thanks lot.
jordy
here's more complete solution:
declare @collist nvarchar(max) set @collist = stuff((select distinct ',' + quotename(name) table -- table here xml path(''), type ).value('.', 'nvarchar(max)') ,1,1,'') declare @q nvarchar(max) set @q = ' select * ( select applicationname, name, value ( select *, row_number() on (partition applicationname, name order createdon desc) rn table -- table here appname = ''contoso'' ) x rn = 1 ) source pivot ( max(value) name in (' + @collist + ') ) pvt ' exec (@q)
Comments
Post a Comment