|
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?
Navigation:
[Reply to this message]
|