4
How to concatenate the values of the same table
Table example
| Usuario | Formulario | Acao | Permitir |
| Admin | Contrato | Imprimir | 1 |
| Admin | Contrato | Consultar | 1 |
| Admin | Contrato | Editar | 0 |
| Admin | Contrato | Excluir | 1 |
Return
| Formulario | Acao |
| Contrato | Imprimir; Consultar; Excluir |
On return, I must always select the Form, and the Action concatenate only when Allow equals 1.
My code
SELECT
FormID,
STUFF((
SELECT ', ' +CAST(AcaoID AS VARCHAR(MAX))
FROM PermissaoAcoesForms
WHERE (FormID = Results.FormID) AND FormID = 'CarteiraCompras' AND Permitir = 1 AND GrupoUsuario = 'Admin'
FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)')
,1,2,'') AS AcaoID
FROM PermissaoAcoesForms Results
GROUP BY FormID
But my return is bringing wrong
Thank you! I’ll test!
– Igor Lessa
@Igorlessa, did it work? That’s what you wanted?
– Emerson JS
Yes! Thank you very much, I made some modifications and used Stuff, thank you very much, helped a lot!
– Igor Lessa
I’m glad the answer was helpful, friend!
– Emerson JS