Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Value List Q of Q Question

LEGEND ,
Aug 27, 2009 Aug 27, 2009

I run a Stored Procedure which brings back a query object.  Some of the column names of that query object have two words.  For example, let's say a field was called "one two".   I know I can output this data with array notation

#queryname["one two"][currentrow]#

but what I really want to do is to create a value list from that field, run another database query based on that list, and then do a Q of Q, using "one two" in the where clause.

Everything I have tried so far with both valuelist () and Q of Q has resulted in a syntax error.  Has anyone ever successfully accomplished this?

870
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Aug 27, 2009 Aug 27, 2009

<cfoutput>
    #arrayToList(q1["one two"])#
</cfoutput>

That would work for the valueList. I do not know of any way to reference an invalid column name directly in a QoQ.  But you could always rename the column so to speak ..

     <cfset queryAddColumn(myQuery, "NewColumnName", myQuery["one two"]) />

Translate
Valorous Hero ,
Aug 27, 2009 Aug 27, 2009

<cfoutput>
    #arrayToList(q1["one two"])#
</cfoutput>

That would work for the valueList. I do not know of any way to reference an invalid column name directly in a QoQ.  But you could always rename the column so to speak ..

     <cfset queryAddColumn(myQuery, "NewColumnName", myQuery["one two"]) />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2009 Aug 27, 2009

I ended up using QueryAddColumn.  I was wondering if I could work with the original query.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 27, 2009 Aug 27, 2009
LATEST

If you use QueryAddColumn, you can still use the original query.  But I do not know of any way to reference the invalid column name in a QoQ. AFAIK, you must use the renamed column instead

<cfquery name="myQuery" datasource="SomeDSN">
    SELECT 'b' AS [One Two] UNION
    SELECT 'c' AS [One Two] UNION
    SELECT 'd' AS [One Two] UNION
    SELECT 'a' AS [One Two]
</cfquery>

<cfset queryAddColumn(myQuery, "NewColumnName", myQuery["one two"]) />

<cfquery name="newQuery" dbtype="query">
    SELECT    *
    FROM    myQuery
    WHERE    NewColumnName LIKE '%something%'
</cfquery>
<cfdump var="#newQuery#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources