<CFQUERY NAME="GetResults" DATASOURCE="OWS">
SELECT 
   M.MerchID, M.MerchName, M.MerchDescription, 
   C.LastName
FROM
   Contacts C, Merchandise M, MerchandiseOrders O, MerchandiseOrdersItems OI
WHERE
       M.MerchID = OI.ItemID AND
       OI.OrderID = O.OrderID AND
       O.ContactID = C.ContactID
ORDER BY
       M.MerchID
</CFQUERY>

<!--- Create new query with same column names --->
<CFSET MerchCustomers = QueryNew(GetResults.ColumnList)>
<CFOUTPUT QUERY="GetResults" GROUP="MerchID">
  <!--- Make a comma-separated list of all papers for this MerchID --->
  <CFSET LastNameList = "">
  <CFOUTPUT><CFSET LastNameList = ListAppend(LastNameList, GetResults.LastName)></CFOUTPUT>
  <!--- Make new row in MerchCustomers, with other data just copied from
  [ic:ccc]GetResults --->
  <CFSET Temp = QueryAddRow(MerchCustomers)>
  <CFSET Temp = QuerySetCell(MerchCustomers,"MerchID",GetResults.MerchID)>
  <CFSET Temp = QuerySetCell(MerchCustomers,"MerchName",GetResults.MerchName)>
  <CFSET Temp = QuerySetCell(MerchCustomers,"MerchDescription",GetResults.MerchDescription)>
  <CFSET Temp = QuerySetCell(MerchCustomers,"LastName",LastNameList)>
</CFOUTPUT>

<CFINDEX 
   ACTION="UPDATE"
   COLLECTION="Merchandise"
   KEY="MerchID"
   TYPE="CUSTOM"
   TITLE="MerchDescription"
   QUERY="MerchCustomers"
   BODY="MerchDescription, LastName"
>

<HTML>

<HEAD>
<TITLE>Indexing Complete</TITLE>
</HEAD>

<BODY>

<H2>Indexing Complete</H2>

</BODY>

</HTML>
