To expand upon my last question regarding a SQL query or C# code that can pivot or transpose values in one column into distinct columns based on data from another column:
Upon further inspection of the data I need a script or query that can convert row values in one column into distinct columns based on values in two other columns.
So for example, here is my current data table:
ID USERID ATTRIBUTE ATTRIBUTE VALUE
00001 15 Entitlement 80
00001 15 Entitlement 81
00001 15 Permission 90
00001 15 Permission 91
00001 15 Permission 92
00001 16 Entitlement 82
00001 16 Permission 93
I would need the output table to look like:
ID USERID ENTITLEMENT PERMISSION
00001 15 80 90
00001 15 81 91
00001 15 92
00001 16 82 93
Where the values in the ENTITLEMENT and PERMISSION column are grouped by USERID.
I understand there will be Null values in either new columns when the row count between them doesn't match, and that's ok, as long as each new column contains all the row values and correspond with the correct USERID.
Pivoting the data using T-SQL, i.e.
select ID, USERID, ENTITLEMENT, PERMISSION from dbo.Test_Table
pivot (Max(ATTRIBUTE VALUE) for Attribute IN ([ENTITLEMENT], [PERMISSION])) as PivotTable
order by ID asc
...doesn't return all values due to the MAX aggregate.
The C# code in the previous answer works fine, but, again, only considers ATTRIBUTE VALUE column.
Once again, any help with this task is appreciated. C# is not my forte.