0

Context I want to retrieve data about accounts and their associated user roles. Since we are using a low code framework the relations are kept in a separate table as well (association of account and user role, besides account and user role table). We use MS SQL.

Current situation: When I do the following query I do get the users and roles, but they are on seperate lines. I want to concatenate the roles of same user into same value :

select  us.name, * from administration$account a
inner join system$userroles uss on a.id = uss.system$userid 
inner join system$userrole us on us.id=uss.system$userroleid

Results in

Role                    id                  name    system&userid      system$userroleid  id
LocationManager         41939771529887748   Britt   41939771529887748  4785074604081160  4785074604081160
PlacementManager        41939771529887748   Britt   41939771529887748  4785074604081353  4785074604081353

Required situation: This should be merged like

Role                                 Name
LocationManager,PlacementManager     Britt

Question: How should the query be with respecting the inner joins per account, so that you see per all the user roles of that account in one row?

user3394645
  • 87
  • 2
  • 11
  • please have a look on STRING_AGG-function in MS SQL Server https://learn.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-ver16 – Sergey Mar 25 '23 at 11:53
  • Take a look at this blog. [link](https://www.mssqltips.com/sqlservertip/2914/rolling-up-multiple-rows-into-a-single-row-and-column-for-sql-server-data/) – LearnItDom Mar 25 '23 at 20:47

0 Answers0