Please, in the query below I want you to bring it as follows.
contato andreia, marcos, juliana
ie on the same line. In the query, I used stuff
, but to no avail. Today she's bringing it that way.
contato andreia marcos juliana
Follow the query:
--Contatos vinculados a contas cadastradas de 17/11/2015 até hoje, sem oportunidades cadastradas--
select distinct
U.UsuID Usuid,
U.UsuNome Nome_Fantasia, U.UsuRazaoSocial Razão_Social,
A.Descricao ABC,
U.UsuCGC CNPJ,
t.UsuNome,
U.UsuUF,
U.UsuCidade,
CP.CompDesc Qtde_CNPJs,
R.RamoDesc,
contato = STUFF(
(SELECT ',' + t1.UsuNome
FROM usuario t1
WHERE t1.UsuID = ur.UsuID
FOR XML PATH(''), TYPE).value('(./text())[1]', 'VARCHAR(MAX)') 1, 1, '')
from CRMDetalhesConta DCT
left join Usuario U
on (U.UsuID = DCT.ContaID)
left join CRMDetalhesContato DCO
on (DCT.ContaID = DCO.ContaID)
left join Usuario UR
on (UR.UsuID = DCO.ContatoID)
INNER JOIN ComplementoColunas C ON U.UsuID = C.UsuID AND C.LinhaID = 1
AND CompID = 32
AND C.ColunaID = 12
LEFT JOIN Complemento CP ON CP.UsuID = U.UsuID AND CP.CompID = 1
INNER JOIN Usuario T ON t.UsuID = c.ColunaValor
LEFT JOIN CRMRamo R ON R.RamoID = DCT.RamoID
LEFT JOIN CurvaABC A ON A.CurvaID = U.CurvaID
where t.UsuID in (38)
AND U.UsuRazaoSocial IS NOT NULL
AND u.EmpLiberada= 1 AND U.UsuTipo = 'C'
AND U.UsuID NOT IN (select UsuIDCliente from Tarefa where TarTipID in (710) and TarStatus in (0,1,5))
AND U.UsuID not in (select UsuIDCliente from Tarefa where TarTipID in (710) and CONVERT(DATE,TarFechamento) BETWEEN '01-01-2018' and getdate())
and u.UsuID = 83295
order by U.UsuID