SQLTeam.com | Weblogs | Forums

Concatenate rows in sql server


#1

I want to concatenate rows of product_code column where it has duplicates Iin ID.

SELECT ORDER_DETAIL.ORDER_NO, ORDER_DETAIL.ORDER_LINE_NO, ORDER_DETAIL.ORDER_DATE, ORDER_DETAIL.PRODUCT_CODE, ORDER_DETAIL.PARENT_PRODUCT,
ORDER_DETAIL.INVOICE_DATE, ORDER_DETAIL.LINE_STATUS_CODE, ORDER_DETAIL.SHIP_MASTER_CUSTOMER_ID, ORDER_DETAIL.SHIP_SUB_CUSTOMER_ID,
ORDER_DETAIL.ACTUAL_TOTAL_AMOUNT, PRODUCT.PRODUCT_CLASS_CODE, ORDER_MASTER.MARKET_CODE AS [Order Master Market Code],
MKT_MARKET_MASTER.DESCRIPTION AS [Order Master Market Code Description], ORDER_DETAIL.MARKET_CODE, MKT_MARKET_MASTER_1.DESCRIPTION,
ORDER_DETAIL.CYCLE_END_DATE
FROM ORDER_DETAIL LEFT OUTER JOIN
MKT_MARKET_MASTER AS MKT_MARKET_MASTER_1 ON ORDER_DETAIL.MARKET_CODE = MKT_MARKET_MASTER_1.MARKET_CODE LEFT OUTER JOIN
MKT_MARKET_MASTER RIGHT OUTER JOIN
ORDER_MASTER ON MKT_MARKET_MASTER.MARKET_CODE = ORDER_MASTER.MARKET_CODE ON
ORDER_DETAIL.ORDER_NO = ORDER_MASTER.ORDER_NO LEFT OUTER JOIN
PRODUCT ON ORDER_DETAIL.PRODUCT_ID = PRODUCT.PRODUCT_ID
WHERE (ORDER_DETAIL.PARENT_PRODUCT = '17LV') AND (ORDER_DETAIL.LINE_STATUS_CODE <> 'P') AND (PRODUCT.PRODUCT_CLASS_CODE = 'SEM')


#2

This view lists WorkerNumbers assigned to staff flattened out in a column separated by ', '