Monday, July 09, 2007

SQL Table to Comma Delimted String

I always wondered how to turn the results of a SQL query INTO a delimited string. On a whim I did a google search today and found out how. The technique actually isn't that complex.

Check out how by clicking [HERE].

Here is a primitive example of how it is done from the above page.

DECLARE @p_str VARCHAR(1000)
SET @p_str = ''

SELECT @p_str = @p_str + ',' + CAST(productid AS VARCHAR(6))
FROM [order details]
WHERE orderid = @p_order_id

No comments: