Using SQL Server 2017, I am running a fairly straightforward query of:
SELECT SecCode,Allowed FROM Security
And that is returning a fairly straightforward table as shown here:
| SecCode | Allowed | 
|---|---|
| MNCUPR | GroupA | 
| SEC000 | GroupB,GroupC | 
| SEC001 | GroupA,GroupC | 
| SEC005 | GroupD | 
| SEC007 | GroupA,GroupB,GroupD | 
I am trying to determine what options I have (if any) to perform a few additional tasks in this query:
- Split the results in 'Allowed' by comma, giving me separate entities/tokens for each Group in a given row.
- Run an additional query of: SELECT Users from Users WHERE GroupList LIKE %GROUP_FROM_MAIN_QUERY%
Hopefully returning something like:
| SecCode | Allowed | 
|---|---|
| MNCUPR | Adam,Alex | 
| SEC000 | Billy,Bobby,Charlie,Chuck,Charles | 
| SEC001 | Adam,Alex,Charlie,Chuck,Charles | 
| SEC005 | Dylan,David | 
| SEC007 | Adam,Alex,Billy,Bobby,Dylan,David | 
Would this best be handled by a stored procedure? Or some form of a cte?
I'm open to any suggestions, as I am using this as more of a learning experience than anything else.
