Month: August 2017

php – DataTables – Dynamic Columns From Ajax Data Source? – Stack Overflow

Source: php – DataTables – Dynamic Columns From Ajax Data Source? – Stack Overflow

Advertisements

pivot sql server

SELECTSELECT R.UserID, R.RoleIDFROM User_Role R;
DECLARE @cols AS NVARCHAR(MAX),    @query  AS NVARCHAR(MAX)
select @cols = STUFF((SELECT DISTINCT ‘,’ + QUOTENAME(RoleID)                     from User_Role                    group by UserID,RoleID            FOR XML PATH(”), TYPE            ).value(‘.’, ‘NVARCHAR(MAX)’)         ,1,1,”)
set @query = ‘SELECT ‘ + @cols + ‘ from              (                select UserID,RoleID                from User_Role            ) x            pivot             (                UserID                for RoleID in (‘ + @cols + ‘)            ) p ‘
execute(@query);
select * from yourtable