Solved

queryNew Help in coldfusion

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion scheduled tasks as one task 2 79
Tech Writing Terminology - Pane or Panel? 8 77
How to get statistic's from a competitors website?! 1 87
Problem to page 4 74
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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…

896 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

11 Experts available now in Live!

Get 1:1 Help Now