Mike,

Although it's not possible to return a comma delimited list of
values from a subquery in the select statement, maybe the this
block of test code will help you produce the results you're
looking for:

<cfquery name="UserTasks" datasource="test">
     select u.username, t.taskname
     from users u inner join usertasks ut on (u.userid =
ut.userid)
            inner join tasks t on (ut.taskid = t.taskid)
     order by t.taskname, u.username
</cfquery>

<cfdump var="#UserTasks#"><!--- test tool: remove later --->

<p>

<cfparam name="prev_task" default="">
<cfparam name="userlist" default="">
<cfparam name="num" default = 1>

<table>

<tr>
     <th align="left">Task</th>
     <th width="25">&nbsp;</th>
     <th align="left">User</th></tr>

<cfoutput query="UserTasks">

 <cfif taskname is not prev_task>
      <cfif num is not 1>
           <td>#variables.userlist#</td></tr>
      </cfif>
      <tr><td>#taskname#</td><td>&nbsp;</td>
      <cfset userlist = "">
      <cfset userlist = ListAppend(userlist, #username#)>
 <cfelse>
      <cfset userlist = ListAppend(userlist, #username#)>
      <cfif num is UserTasks.recordcount>
           <td>#variables.userlist#<td></tr>
      </cfif>
 </cfif>

 <cfset prev_task = taskname>
 <cfset num = incrementvalue(num)>

</cfoutput>


</table>





----- Original Message -----
From: "Haggerty, Mike" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, October 08, 2002 1:32 PM
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?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