Solved

queryNew Help in coldfusion

Posted on 2012-04-09
2
377 Views
Last Modified: 2012-06-27
I need help creating a query in coldfusion. I have 2 loops. I will give me an ID. But the second loop must create as many columns as loop recordcount is.Instead i getting an error message

The column name (mydata_1) that you specified already exists in this query.
Column names must be unique.  
myQueryTest = QueryNew("");
var IDArr = ArrayNew(1);
for (k = 1;k lte ArrayLen(List);k++) {
var locID = list[k];
  QueryAddRow(myQueryTest );
  IDArr[k] = locID;
var myDataArr = ArrayNew(1);

for (kk = 1;kk lte ArrayLen(DataColumns);kk++) {
 
nColumnNumber= QueryAddColumn(myQueryTest,"mydata_#k#_#kk#","VarChar",myDataArr);      
}



}
nColumnNumber= QueryAddColumn(myQueryTest, "ID", "VarChar", IDArr);
0
Comment
Question by:erikTsomik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37824085
If only the "ID" column is populated, you don't need all that.  Just generate the dynamic columns first:

     myQueryTest = queryNew();
     emptyArray = [];
     for (kk = 1;kk lte ArrayLen(DataColumns);kk++) {
        QueryAddColumn(myQueryTest,"mydata_#k#_#kk#","VarChar", emptyArray );      
     }

Then use the #list# array to add and populate the "ID" column

        QueryAddColumn(myQueryTest, "ID","VarChar", list);
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37824350
> myQueryTest = queryNew();

Oops, obviously add quotes there :)  ie QueryNew("")
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question