Solved

queryNew Help in coldfusion

Posted on 2012-04-09
2
367 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now