Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I concatenate multiple row results to one line?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/9139472/concatenate-grouped-rows">Concatenate grouped rows</a> </p> </blockquote> <p>I am working with this table:</p> <pre><code>fecha cliente preg resp puntos calif pagoxejec 2009-03-28 00:00:00 2005 9 23 1 94 5 5 2009-03-28 00:00:00 2005 9 31 1 94 5 5 2009-03-28 00:00:00 2005 9 32 1 55 3 3 2009-03-28 00:00:00 2005 9 33 1 37 2 2 2009-03-28 00:00:00 2005 9 34 0 0 0 0 2009-03-28 00:00:00 2379 7 8 1 0 35 35 </code></pre> <p>(This has more records.)</p> <p>I have a table called <code>cliente</code> and now this is my query:</p> <pre><code>DECLARE @supervisor varchar(50)/* sera una cadena de tipo 1 ó 3,4,5 para usarse como supervisor in (@supervisor)*/ DECLARE @fechainicial datetime /*será la fecha inicial tomada*/ DECLARE @fechafinal datetime /*será la fecha final tomada*/ SET @supervisor='1,2,3,4' SET @fechainicial='2009-02-1 00:00:00.000' SET @fechafinal='2009-03-19 00:00:00.000' SELECT smerc.cliente, nivelmkt nivel, MAX(fecha) ultima, preg, resp FROM smerc INNER JOIN clientes on smerc.cliente=clientes.cliente WHERE fecha BETWEEN @fechainicial AND @fechafinal AND resp=1 GROUP BY smerc.cliente, preg, resp, nivelmkt ORDER BY smerc.cliente </code></pre> <p>And some results:</p> <pre><code>cliente nivel ultima preg resp 892 1 2009-03-03 00:00:00 2 1 892 1 2009-03-03 00:00:00 3 1 892 1 2009-03-03 00:00:00 6 1 892 1 2009-03-03 00:00:00 23 1 892 1 2009-03-03 00:00:00 32 1 892 1 2009-03-03 00:00:00 34 1 892 1 2009-03-03 00:00:00 44 1 892 1 2009-03-03 00:00:00 999 1 1889 1 2009-03-03 00:00:00 2 1 </code></pre> <p>The <code>nivel</code> table:</p> <pre><code> nivel preg nomtiny 1 1 E 1 2 OME 1 3 EX 1 4 EP 1 5 E7 1 6 ROT 1 11 H 1 12 PPA 1 21 PDV 1 23 CDP 1 31 EXI 1 32 PLC 1 33 COP 1 34 PM 1 40 O 1 41 PAP 1 44 NCA 1 999 PRP 2 1 E </code></pre> <p>Now i need next result:</p> <pre><code>cliente nivel preg nomtiny 892 1 1 E 892 1 4 EP 892 1 5 E7 892 1 11 H 892 1 12 PPA 892 1 21 PDV 892 1 31 EXI 892 1 33 COP 892 1 40 O 892 1 41 PAP </code></pre> <p>You can see on <code>smerc (BETWEEN @fechainicial AND @fechafinal)</code> this client on the last result doesn't have this spreguntas'records or respuesta=0</p> <blockquote> <p>(2 condition client doesn't have this preg, (with cliente'nivel) or he does have this record but with resp equal to 0 )</p> </blockquote> <p>Then my final result must be this:</p> <pre><code>client allnomtinyforthisclient 892 E,EP,E7,H,PPA,PDV,EXI,COP,O,PAP </code></pre> <p>How do I get multiple rows to appear on one line as above?</p> <p>server is sql 2005</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload