January 14, 2003 at 6:14 pm
How do I concatenate the values of multiple rows into a single column of a given table?
For example, in the Northwind Database, in the Order Details table, I want to be able to display the following two-column report:
OrderID ProductIDListing
10248 11,42,72
10249 14,51
10250 41,51,65
etc.........
In above report, there is only be one record for each OrderID. In the ProductIDListing column, it should list out all the product IDs that are in that OrderID.
FYI, the Order Details table has the following columns:
OrderID
ProductID
UnitPrice
Quantity
Discount
Thanks in advance.
Sincerely,
Billy
Edited by - bp on 01/14/2003 6:14:59 PM
Edited by - bp on 01/14/2003 6:15:38 PM
January 14, 2003 at 6:29 pm
To concatenate an entire column together use the foloowing code. To accomplish your task you may want to do something more advanced but here is a main idea:
DECLARE@rowVARCHAR( 1000 )
SET@row = ''
SELECT@row = @row + ', ' + ISNULL( CAST( ProductID AS VARCHAR( 2 ) ), '' )
FROMOrderDetail
PRINT @row
Edited by - mromm on 01/14/2003 6:30:09 PM
January 14, 2003 at 7:21 pm
thanks mromm for the idea!
cheers!
Billy
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply