Reply to Re: Return subquery rows as one delimited column

Your name:

Reply:


Posted by KoliPoki on 10/29/06 22:35

Without using a cursor but u still need to declare a variable:

DECLARE @foo varchar(900) SELECT @foo = COALESCE(@foo + ',', '') +
CAST(foo AS varchar(120)) FROM tbl1 WHERE foo <> '' SELECT
ISNULL(@foo,'') AS foo')

If you're using it in a query u can wrap it in a function and do
"select foo from dbo.fn_foo()".

Or use a cursor and wrap it in a function.

R.






kingskippus@gmail.com wrote:
> I don't know if this is possible, but I haven't been able to find any
> information.
>
> I have two tables, for example:
>
> Table 1 (two columns, id and foo)
> id foo
> --- -----
> 1 foo_a
> 2 foo_b
> 3 foo_c
>
> Table 2 (two columns, t1_id, and bar)
> t1_id bar
> ------ ----
> 1 bar_a
> 1 bar_b
> 1 bar_c
> 2 bar_d
> 3 bar_e
> 3 bar_f
>
> What I'm shooting for is returning the result of a subquery as a
> text-delimited column. In this example, using a comma as the
> delimiter:
>
> Recordset Returned:
> foo bars
> ----- -----
> foo_a bar_a,bar_b,bar_c
> foo_b bar_d
> foo_c bar_e,bar_f
>
> I know that it's usually pretty trivial within the code that is
> querying the database, but I'm wondering if the database itself can do
> this.
>
> Is this possible, and if so, can someone please point me to how it can
> be done?

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация