Skip to main content
Known Participant
February 23, 2009
Question

Query of Queries Help

  • February 23, 2009
  • 2 replies
  • 363 views
I have the following query. It calculates a total value, then sums that total value for each site. I usd cast and divide by 1000 to eliminate the decimals and turn the remainder into a string.

<cfquery name="openValue" datasource="dbName">
SELECT cast(SUM(totalValue)/1000 as int) AS sumTotalValue, Site FROM
(
SELECT DISTINCT (a.quantity * a.value_amount) AS totalValue,
b.site
FROM UnReceivables_URDN a
INNER JOIN UnReceivables_Site_Master b
ON a.Site_ID = b.Site_ID
WHERE currentState NOT IN ('Voided','Closed')
GROUP BY a.quantity, a.value_amount, b.site
) AS I
WHERE site like '%%'
GROUP BY Site
ORDER BY Site
</cfquery>

I then want to use query of queries to take that converted string and concantenate it with the site. But I get an error saying (. is not in the select list.

<cfquery name="openValue1" dbtype="query">
select cast(sumTotalValue as varchar(10)) + site as newSite
from openValue
</cfquery>

I have never had any success usinq query or queries. It only seems to work if it is just a simple select. If you try to do other things with it, there is an error. I want to use views instead.

What is wrong with my query of queries. The tables are in sql server.
    This topic has been closed for replies.

    2 replies

    Participating Frequently
    February 23, 2009
    I tried to find it quickly - but somewhere out there is a list of operators that CF QoQ's support. But I believe Dan is right in that there's isn't a concatonate operator.

    Like Dan said, you could do it all in one shot in the original query. Alternatively, you can just loop over the data and modify it as necessary.

    Something along the lines of:

    <cfset QueryAddColumn(openValue,"newSite","varchar",ArrayNew(1))>

    <cfloop query="openValue">
    ___<cfset newSite = sumTotalValue & site>
    </cfloop>

    Inspiring
    February 23, 2009
    I'm not sure if you can concatonate with q of q. I've never tried.

    Why don't you simply do it in your query?