I just helped someone on the House of Fusion CF-Talk list who was having trouble with his ColdFusion query of queries. Like some of us do, he was declaring a local variable, LOCAL, in a function and then declaring variables within it. This is done so that only one variable (LOCAL) has to be "var'ed" to enable many variables to be considered local to the function's memory space:
// Declare local scope. var LOCAL = StructNew(); // These are now all local. LOCAL.Foo = 1; LOCAL.Bar = QueryNew( "id" ); LOCAL.Test = StructNew();
His problem was that he was doing a query of queries using a query stored in the LOCAL pseudo scope:
<cfquery name="qTest" dbtype="query"> SELECT id, name FROM LOCAL.Data </cfquery>
This throws the error:
Query Of Queries syntax error.
This can be frustrating because if you change the name LOCAL to something like LOCAL2, it works just fine. The problem, while frustrating, has a very simple answer: LOCAL is a reserved word in SQL and ColdFusion Query of Query SQL. The solution: use the [ ] notation:
<cfquery name="qTest" dbtype="query"> SELECT id, name FROM [LOCAL].Data </cfquery>
Want to use code from this post? Check out the license.