Ok, the goal is to take this PurchaseOrderHeader table from the AdventureWorks db and build a comma delimited string of purchase orders.
Filtered dataset:
PurchaseOrderId OrderDate SubTotal
————— ———————– ———
801 2003-10-05 00:00:00.000 143.0415
884 2003-10-12 00:00:00.000 143.0415
907 2003-10-14 00:00:00.000 143.0415
971 2003-10-28 00:00:00.000 143.0415
DECLARE
@PurchaseOrders varchar(50)
>
SELECT
@PurchaseOrders = ISNULL(@PurchaseOrders + ‘,’, ”) + CONVERT(varchar(10), PurchaseOrderId)
FROM Purchasing.PurchaseOrderHeader
WHERE VendorId = 1
AND OrderDate BETWEEN ‘10/1/2003′ AND ‘10/31/2003′>
SELECT
@PurchaseOrders>
This returns:
801,884,907,971
