I have a query and I want to group data from a column in a row, separated by commas, through examples I have been able to put together the following query, but when I execute it I get The multi-part identifier "arr_inventario_sal.ains_folio" could not be bound
SELECT arr_inventario_sal.ains_folio,
STUFF((SELECT ', ' + arr_inventario_sal.ains_num_serie AS Expr1
FROM arr_inventario_sal INNER JOIN
mov_inventario ON arr_inventario_sal.ains_folio = mov_inventario.inv_folio
WHERE (mov_inventario.inv_tip_doc_ref = 'FAC') AND (mov_inventario.inv_pto_vta = 'VIC') AND (mov_inventario.inv_fol_doc_ref = 134990) FOR XML PATH('')), 1, 2, '') AS SERIE
When I remove arr_inventario_sal.ains_folio, it throws me the data, but I need to display more columns.
SELECT STUFF
((SELECT ', ' + arr_inventario_sal.ains_num_serie AS Expr1
FROM arr_inventario_sal INNER JOIN
mov_inventario ON arr_inventario_sal.ains_folio = mov_inventario.inv_folio
WHERE (mov_inventario.inv_tip_doc_ref = 'FAC') AND (mov_inventario.inv_pto_vta = 'VIC') AND (mov_inventario.inv_fol_doc_ref = 134990) FOR XML PATH('')), 1, 2, '') AS SERIE
Do you have any suggestions to carry out my query?
It is happening because you are trying to choose a column that is not in your subquery (which you have to do the stuff)
Since I'm not very steeped in the final result of your query, I'll leave you what I understand it should be