Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Need to dynamically add grouping based on username

$
0
0
HiI have this simple query:[code="sql"] SELECT CompanyName as Company, Batch, USERNAME as [User Name], SQLUserName as [System User Name], --claim_form_type_id as [Claim Form Type], CASE WHEN [claim_form_type_id] IS NULL THEN ('N/A') END as [Claim Form Type], Claim_type as [Claim Type],--altered status_type as [Status Type], each as [Each], member_last as [Member Name], fromdate as [From Date], todate as [To Date], CASE WHEN [Status_Type] = 'Entered' THEN 1 ELSE 0 END AS Entered, CASE WHEN [Status_Type] = 'Approved' THEN 1 ELSE 0 END AS Approved, CASE WHEN [Status_Type] = 'Pending' THEN 1 ELSE 0 END AS Pending FROM Report_data[/code]The results come in fine but I need to add columns based on the [user name]. So that I end up with the number of claims per user name - but as additional columns. In other words - if user XYZ has 55 approved I need a column that says XYZ 55 approved and XYZ has 66 pending, etc. I still need the 'entered' as 1 columns.

Viewing all articles
Browse latest Browse all 3145

Trending Articles