This explains why I didn't understand how coallesce was supposed to produce
a comma delimited list...

DECLARE @EmployeeList varchar(100)

SELECT @EmployeeList = COALESCE(@EmployeeList + ',', '') +
   CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1

SELECT @EmployeeList

There are a number of "hacks" going on here -- it _must_ be SELECT @mylist =
COALESCE(... and not SELECT COALESCE(... which just returns one row for each
item you want in the list. You can put the above code in a <cfquery> tag,
but it won't return the list ( actually the query is undefined after running
it, although it runs okay ) -- at least that's my experience using the odbc
drivers in cf 5 ... so it would have to be in a stored procedure to get
anything out of it... But in those unique instances where you really want a
list in a column from the db, this would be really useful. :)

Isaac
Certified Advanced ColdFusion 5 Developer

www.turnkey.to
954-776-0046

> You may want to look at this
> http://www.sqlteam.com/item.asp?ItemID=2368

> I tried this a few weeks ago. Seems that it needs to be a
> stored procedure
> to run. I was looking for a solution that involved a
> simple query.  But, it
> may help you.

> Mark W. Breneman
> -Macromedia Certified ColdFusion Developer
> -Network / Web Server Administrator
>   Vivid Media
>   [EMAIL PROTECTED]
>   www.vividmedia.com
>   608.270.9770

> -----Original Message-----
> From: Haggerty, Mike [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 08, 2002 1:32 PM
> To: CF-Talk
> Subject: Return a Sub-Query as a Comma Delimited List


> The subject line says it all... I am writing a query for
> MS SQL Server and
> need to return a comma delimited list of values from a
> subquery in the
> select statement. Anyone know a way to do this?

> For instance, I have a tasks table, a users table, and a
> reference table
> linking multiple users to tasks. I want each row of the
> results to display
> the task title along with a comma delimited list of the
> names of users
> assigned to the task.

> Normally, this is something I would do in CF by grouping
> the output, but in
> this instance it is important to return the results
> without grouping them.

> Any help is appreciated, thanks,

> M


> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~|
> Archives:
> http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
> Subscription: http://www.houseoffusion.com/index.cfm?sideb
> ar=lists&body=lists/cf_talk
> FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
> Your ad could be here. Monies from ads go to support these
> lists and provide more resources for the community.
> http://www.fusionauthority.com/ads.cfm



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to