I have a problem in a query, where I need to concatenate records from a table. I need select
to take the FormID
and concatenate the records of AcaoID
only if Permitir
is 1. p>
Query:
Declare @Result varchar(MAX)
Declare @FormID varchar(MAX)
Set @Result = ''
Select @FormID = FormID, @Result = COALESCE(@Result + AcaoID + '; ', '') FROM PermissaoAcoesForms
where GrupoUsuario = '{0}' AND FormID = '{1}' AND Permitir = '1'
if @Result <> '' Begin
Set @Result = SUBSTRING(@Result, 1, LEN(@Result) - 1) end
Select @FormID as FormID, @Result as AcaoID
The problem is that when I scroll to query
, if FormID
exists and Permitir
equals 0, it returns nothing.
In this case I need to return FormID
regardless of the value of Permitir
, but if Permitir
is 1 it has to concatenate all records where Permitir
is 1.