0
I have a problem with a query, where I need to concatenate records from a table. I need the select
take the FormID
and concatenate the records of AcaoID
only if Permitir
for 1.
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 turn the query
, case FormID
exists and Permitir
is equal to 0, it returns nothing.
In that case I must return FormID
regardless of the value of Permitir
, but case Permitir
be 1 he has to concatenate all records where Permitir
be 1.
Are these three fields from the same table? If yes, they no longer return on the same query line?
– Fleuquer Lima
Yes yes, they are from the same table. I need to return
FormID
regardless of the value ofPermitir
, in my query just returnFormID
casePermitir
be 1– Igor Lessa
but you are declaring it in the Where: "AND Allow" = '1', if the value of allow does not matter, just take it out of the clause
– Fleuquer Lima
Is that my frontend displays the result only of assets (when
Permitir
is equal to 1)– Igor Lessa