How to create a query to Concatenate

D

DawnTreader

Hello All

I need to take this:

COID WOID
54621 04858
54621 04859
55106 10000
55106 10388
55384 10007
55384 10289
55384 16470
60000 10011
60000 10013
60000 10059

and turn it into this:

COID WOIDs
54621 4858, 4859
55106 10000, 10388
55384 10007, 10289, 16470
60000 10011, 10013, 10059

my sql at the moment:

SELECT
dbo_CUST_ORDER_LINE.CUST_ORDER_ID AS COID,
dbo_DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID AS WOID
FROM
((dbo_CUST_ORDER_LINE
LEFT JOIN dbo_CUST_LINE_BINARY
ON (dbo_CUST_ORDER_LINE.LINE_NO = dbo_CUST_LINE_BINARY.CUST_ORDER_LINE_NO)
AND (dbo_CUST_ORDER_LINE.CUST_ORDER_ID =
dbo_CUST_LINE_BINARY.CUST_ORDER_ID))
LEFT JOIN dbo_DEMAND_SUPPLY_LINK
ON (dbo_CUST_ORDER_LINE.LINE_NO = dbo_DEMAND_SUPPLY_LINK.DEMAND_SEQ_NO)
AND (dbo_CUST_ORDER_LINE.CUST_ORDER_ID =
dbo_DEMAND_SUPPLY_LINK.DEMAND_BASE_ID))
LEFT JOIN dbo_WORK_ORDER
ON (dbo_DEMAND_SUPPLY_LINK.SUPPLY_SUB_ID = dbo_WORK_ORDER.SUB_ID)
AND (dbo_DEMAND_SUPPLY_LINK.SUPPLY_SPLIT_ID = dbo_WORK_ORDER.SPLIT_ID)
AND (dbo_DEMAND_SUPPLY_LINK.SUPPLY_LOT_ID = dbo_WORK_ORDER.LOT_ID)
AND (dbo_DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID = dbo_WORK_ORDER.BASE_ID)
WHERE
(((dbo_DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID) Is Not Null))
GROUP BY
dbo_CUST_ORDER_LINE.CUST_ORDER_ID,
dbo_DEMAND_SUPPLY_LINK.SUPPLY_BASE_ID;

any and all help appreciated. :)
 
J

John W. Vinson

I need to take this:

COID WOID
54621 04858
54621 04859
55106 10000
55106 10388
55384 10007
55384 10289
55384 16470
60000 10011
60000 10013
60000 10059

and turn it into this:

COID WOIDs
54621 4858, 4859
55106 10000, 10388
55384 10007, 10289, 16470
60000 10011, 10013, 10059

It's hard to do in a general sense in SQL, given that you can't a priori
predict the number of WOID's you need. It's simplest to use some VBA code.
There's an example at http://www.mvps.org/access/modules/mdl0004.htm
that you should be able to adapt.
 
Top