Columns W Spaces in QueryAddColumn?
Posted on 2004-08-09
I currently have the following code, which generates an error:
<cfset qNew = QueryNew("Col1") />
<cfset myArray = ArrayNew(1) />
<cfset userInput = "Col 2" />
<cfset QueryAddColumn(qNew,userInput,myArray) />
<cfdump var="#qNew#" />
The error is:
The column name "Col 2" is invalid.
Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
In the code userInput is actually a parameter specified by the user and needs to support variables defined by the user which have spaces. ColdFusion supports field names that have spaces and returned from a database just fine. ColdFusion supports it when a query is returned from a database where the fieldnames have had Alias names with spaces applied to them. Is there an easy way to 'inject' a variable name with a space into the query structure?