View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > QueryNew PreviousNext

QueryNew

Creates an empty query (query object).

An empty query with a set of named columns, or an empty query.

Query functions

QueryNew(columnlist)

QueryAddColumn, QueryAddRow, QuerySetCell

Parameter

Description

columnlist

A string or a variable that contains one. Delimited list of column names, or an empty string.

If you specify an empty string, you can add a column to the query and populate its rows with the contents of a one-dimensional array using QueryAddColumn.

<h3>QueryNew Example</h3>
<p>We will construct a new query with two rows:
<cfset myQuery = QueryNew("name, address, phone")>
<!--- make some rows in the query --->
<cfset newRow = QueryAddRow(MyQuery, 2)>
<!--- set the cells in the query --->
<cfset temp = QuerySetCell(myQuery, "name", "Fred", 1)>
<cfset temp = QuerySetCell(myQuery, "address", "9 Any Lane", 1)>
<cfset temp = QuerySetCell(myQuery, "phone", "555-1212", 1)>
<cfset temp = QuerySetCell(myQuery, "name", "Jane", 2)>
<cfset temp = QuerySetCell(myQuery, "address", "14 My Street", 2)>
<cfset temp = QuerySetCell(myQuery, "phone", "555-1444", 2)>
<!--- output the query --->
<cfoutput query = "myQuery">
<pre>#name#   #address#   #phone#</pre>
</cfoutput>   
To get any element in the query, we can output it individually
<cfoutput>
   <p>#MyQuery.name[2]#'s phone number: #MyQuery.phone[2]#
</cfoutput>

Contents > CFML Reference > ColdFusion Functions > QueryNew PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


mossy_77 said on Jul 22, 2004 at 2:14 AM :
query Functions, there is no faciltity to add arguments to qualify datatypes in custom built queries. this is needed for integers and dates.
No screen name said on Feb 3, 2005 at 12:35 PM :
Hi mossy_77,

You can use CreateODBCDate function and assign a date datatype to a query column and perform your actions basing on that column.

I hope for number you can use Val function for adding a numeric values.

Goodluck,

-- Ravi.
Cal22 said on May 17, 2005 at 6:19 PM :
Can this be used to clear a query's contents before repopulating it?
jrunrandy said on May 24, 2005 at 5:55 PM :
I just added a second <cfset myQuery = QueryNew("name, address, phone")> to the example and it seemed to work for me. Maybe just try it and see how it works for you.
Cal22 said on May 24, 2005 at 9:11 PM :
For clearing the variable, adding <CFSET myQuery=0> seemed to work better and made a big difference in processing time for me. (CF 5.0)
Chris Peters said on Dec 20, 2005 at 7:06 AM :
I agree with mossy_77's comment.

The workarounds everyone suggested do work in most cases. But if you need to do a UNION operation in a Query of Queries (<cfquery dbtype="query">), you cannot use a query created by QueryNew() in unison with a query from another data source.

If you try UNIONing a query from a database with one created from QueryNew(), you get an error similar to this:

Query Of Queries runtime error.
All resulting columns of queries in a SELECT statement containing a UNION operator must have corresponding types.
Columns with index number equal "2" have diffent types (VARCHAR, OTHER).

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa57.htm