473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to I create blank columns using QueryAddColumn?

Haitashi
Hi:

I need to dymanically create a number of columns using the queryAddColumn function.

I was going to use the loop below. That way each column would have a generic dynamically created name.

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="I" from="1" to="#Variables.qProgramDetails.recordcount#">
  2.     <cfset temp = QueryAddColumn(#this.RecordSet#, "Detail#I#", "VarChar", newArray) />
  3. </cfloop>
The problem I'm encountering is that when running that code I get an error that says: "The column name (Detail1) that you specified already exists in this query".

I'm guessing something isn't quite right since apparently on the second iteration of this loop the column name isn't updating to "Detail2".

Any ideas? As always, thanks in advance!! =)
Mar 2 '09 #1
4 5298
acoder
16,027 Expert Mod 8TB
...or perhaps the query already has a column named Detail1. Is this.RecordSet an empty query before the loop?
Mar 4 '09 #2
cymark
2
Try this:

Expand|Select|Wrap|Line Numbers
  1. <cfloop ....>
  2.  
  3.    <cfset col = "Detail"&#I#>
  4.    <cfset temp = QueryAddColumn(#this.RecordSet#, "#col#", "VarChar", newArray) />
  5.  
  6. </cfloop>
Or try dynamic variables - lookup Evaluate function.

Good luck - CM
Mar 9 '09 #3
acoder
16,027 Expert Mod 8TB
cymark, welcome to Bytes and thanks for your contribution.

You could do away with the pound signs in the cfset statement, i.e.
Expand|Select|Wrap|Line Numbers
  1. <cfset col = "Detail"& I>
In this case, however, the code that you've posted won't make a difference because it does recognise "#I#" to be 1 (see error message).
Mar 10 '09 #4
cymark
2
Hi,

Sorry was a bit quick there.

The following seems to work OK:

Expand|Select|Wrap|Line Numbers
  1. <cfset myQuery = QueryNew("")>
  2.  
  3. <cfset FastFoodArray = ArrayNew(1)>
  4. <cfset FastFoodArray[1] = "French Fries">
  5. <cfset FastFoodArray[2] = "Hot Dogs">
  6. <cfset FastFoodArray[3] = "Fried Clams">
  7. <cfset FastFoodArray[4] = "Thick Shakes">
  8.  
  9.  
  10. <cfloop index="I" from="1" to="5">
  11.  
  12.     <cfset col = "Detail"&I>
  13.  
  14.      <cfset temp = QueryAddColumn(#myQuery#, #col#, "VarChar", FastFoodArray) />
  15. </cfloop>
  16.  
  17.  
  18. <cfdump var="#myQuery#">
Creates cols with Detail1, .. to Detail5

Hope it helps...
Mar 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
0
by: Penguin | last post by:
Using Access 97, I've created a grading sheet. To save space, the subjects are in vertical columns on a sub-report, like so: Math Spelling Reading N C T A A E U A I ...
2
by: Amir | last post by:
I really hope someone can explain this behavior. I have spend quite a bit of time and tried a bunch of things, so far nothing has worked. I have a page on which I have a datagrid with template...
1
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a datagrid on a form which is not populated until the user enters selection criteria and clicks a button. Rather than have a blank datagrid when the form is displayed, I would...
10
by: lorirobn | last post by:
Hi, I have a form with several combo boxes, continuous form format, with record source a query off an Item Table. The fields are Category, Subcategory, and Color. I am displaying descriptions,...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
4
by: Techhead | last post by:
I am running into an issue when adding data from multiple columns into one alias: P.ADDR1 + ' - ' + P.CITY + ',' + ' ' + P.STATE AS LOCATION If one of the 3 values is blank, the value LOCATION...
3
by: Max | last post by:
Hello, I have a datagridview object on my form along with some other controls. When the application runs, the datagridview is populated with data from a database. Although the right number of...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.