Multiple values into single cell

Multiple values into single cell

am 18.05.2007 18:03:39 von NAJH

Taking the Northwind database as an example,
I have an order table: 'Orders'
a order details table: 'Order Details'
and a products table: 'Products'

For reasons best ignored, I want to produce a query which has columns:

Orders.OrderID, Products


which has results like:

10248, 'Queso Cabrales, Singaporean Hokkien Fried Mee, Mozzarella di
Giovanni'
10249, 'Tofu, Manjimup Dried Apples'

________
so for those who don't really know what I'm on about and haven't got
access to northwind, I want the second cell to contain the returned
column of a second query (but in text format)

could anyone suggest a way this could be done? am I entering the land
of cursors?

Many thanks,
Neil

Re: Multiple values into single cell

am 18.05.2007 22:47:49 von Erland Sommarskog

NAJH (neilonusenet@yahoo.co.uk) writes:
> For reasons best ignored, I want to produce a query which has columns:
>
> Orders.OrderID, Products
>
>
> which has results like:
>
> 10248, 'Queso Cabrales, Singaporean Hokkien Fried Mee, Mozzarella di
> Giovanni'
> 10249, 'Tofu, Manjimup Dried Apples'
>
> ________
> so for those who don't really know what I'm on about and haven't got
> access to northwind, I want the second cell to contain the returned
> column of a second query (but in text format)
>
> could anyone suggest a way this could be done? am I entering the land
> of cursors?

If you are on SQL 2000, yes. SQL Server MVP Anith Sen covers the various
methods on http://www.projectdmx.com/tsql/rowconcatenate.aspx.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx

Re: Multiple values into single cell

am 20.05.2007 23:41:12 von Joe Celko

>> For reasons best ignored, ... <<

Do not ignore the reasons; so, why do you want to write stinking bad
code?

Re: Multiple values into single cell

am 21.05.2007 04:27:29 von Ed Murphy

--CELKO-- wrote:

>>> For reasons best ignored, ... <<
>
> Do not ignore the reasons; so, why do you want to write stinking bad
> code?

At least he isn't talking about storing the data that way, merely
outputting it that way. That said, I would do it in a separate
reporting layer (e.g. Crystal Reports) if at all possible.

Re: Multiple values into single cell

am 21.05.2007 18:04:51 von NAJH

On May 21, 3:27 am, Ed Murphy wrote:
> --CELKO-- wrote:
> >>> For reasons best ignored, ... <<
>
> > Do not ignore the reasons; so, why do you want to write stinking bad
> > code?
>
> At least he isn't talking about storing the data that way, merely
> outputting it that way. That said, I would do it in a separate
> reporting layer (e.g. Crystal Reports) if at all possible.

I know it's bad practice to do it that way and a seperate reporting
layer like crystal reports etc would be lovely, but I'm in a situation
where I don't have those kind of facilities and budgets at my
disposal. It's just a means to an end. I'm certainly not holding data
like that. It's bad enough dealing with internal politics without
having to deal with it again on here! Thanks to you all for your kind
(or not so kind) input.

Neil