Solved

queryNew Help in coldfusion

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

635 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