4

Is it possible to scope variables when using query of queries? This works

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );

This does not work. It throws an error

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM local.qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );

Message
Query Of Queries syntax error.
Encountered "local. StackTrace java.sql.SQLException:
Query Of Queries syntax error.
Encountered "local. at coldfusion.sql.imq.jdbcStatement.parseSQL(jdbcStatement.java:590) at coldfusion.sql.imq.jdbcStatement.fetchResult(jdbcStatement.java:547) at ORDER BY MenuOrder ", [], {dbtype = "query"} );

3
  • 1
    What does the 2nd sample do that constitutes, "does not"? Commented Nov 4, 2015 at 4:07
  • Try wrapping local within square brackets. Commented Nov 4, 2015 at 4:38
  • [local].qryResult works! Commented Nov 4, 2015 at 4:54

1 Answer 1

7

LOCAL is a reserved word in ColdFusion Query of Query and SQL.

So, wrap LOCAL with square brackets[] like this:

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM [local].qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );

OR

Use some other name for function local scope i.e.,

var newLocal = structNew();
newLocal.qryResult = queryNew("");
return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM newLocal.qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.