I have table with following structure:
I want to show it like this:
Maximum 5 users will be there per LocIC and AuditID
I have table with following structure:
I want to show it like this:
Maximum 5 users will be there per LocIC and AuditID
You want conditional aggregation:
select LocID, AuditID,
max(case when Seq = 1 then userID end) User1,
max(case when Seq = 2 then userID end) User2,
max(case when Seq = 3 then userID end) User3,
max(case when Seq = 4 then userID end) User4,
max(case when Seq = 5 then userID end) User5
from (select *,
row_number() over (partition by LocID, AuditID order by userID) Seq
from table a
) t
group by LocID, AuditID;
You can use group_concat feature SQL server.
select LocID,AuditID, group_concat(userID) listUser from table group by LocID, AuditID
Here later you can use listUser column values to show in table