Solved

queryNew Help in coldfusion

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding a hidden div to each row in a table 6 115
Application.cfc - what is the order of events? 4 91
REGEX HELP 11 62
php mysql check email already in database. (second check) 7 147
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

710 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