<CFQUERY NAME="query_name"
    DATASOURCE="ds_name"
    DBTYPE="type"
    DBSERVER="dbms"
    DBNAME="database name"
    USERNAME="username"
    PASSWORD="password"
    MAXROWS="number"
    BLOCKFACTOR="blocksize"
    TIMEOUT="milliseconds"
    CACHEDAFTER="date" 
    CACHEDWITHIN="timespan" 
    PROVIDER="COMProvider" 
    PROVIDERDSN="datasource" 
    DEBUG="Yes/No">
 
SQL statements
 
</CFQUERY>

CFQUERY passes SQL statements for any purpose to your data source. Not limited to queries.

NAME

Required. The name you assign to the query. Query names must begin with a letter and may consist of letters, numbers, and the underscore character (spaces are not allowed). The query name is used later in the page to reference the query's record set.

DATASOURCE

Required. The name of the data source from which this query should retrieve data.

DBTYPE

Optional. The database driver type:

DBSERVER

Optional. For native database drivers, specifies the name of the database server machine. If specified, DBSERVER overrides the server specified in the data source.

DBNAME

Optional. The database name (Sybase System 11 driver only). If specified, DBNAME overrides the default database specified in the data source.

USERNAME

Optional. If specified, USERNAME overrides the username value specified in the data source setup.

PASSWORD

Optional. If specified, PASSWORD overrides the password value specified in the data source setup.

MAXROWS

Optional. Specifies the maximum number of rows you want returned in the record set.

BLOCKFACTOR

Optional. Specifies the maximum number of rows to fetch at a time from the server. The range is 1 (default) to 100. This parameter applies to ORACLE native database drivers and to ODBC drivers. Certain ODBC drivers may dynamically reduce the block factor at runtime.

TIMEOUT

Optional. Lets you specify a maximum number of milliseconds for the query to execute before returning an error indicating that the query has timed-out. This attribute is not supported by most ODBC drivers. TIMEOUT is supported by the SQL Server 6.x or above driver. The minimum and maximum allowable values vary, depending on the driver.

CACHEDAFTER

Optional. Specify a date value (for example, 4/16/98, April 16, 1998, 4-16-98). ColdFusion uses cached query data if the date of the original query is after the date specified. Effective only if query caching has been enabled in the ColdFusion Administrator. To use cached data, the current query must use the same SQL statement, data source, query name, user name, password, and DBTYPE. Additionally, for native drivers it must have the same DBSERVER and DBNAME (Sybase only).

Years from 0 to 29 are interpreted as 21st century values. Years 30 to 99 are interpreted as 20th century values.

When specifying a date value as a string, make sure it is enclosed in quotes.

CACHEDWITHIN

Optional. Enter a timespan using the ColdFusion CreateTimeSpan function. Cached query data will be used if the original query date falls within the time span you define. The CreateTimeSpan function is used to define a period of time from the present backwards. Effective only if query caching has been enabled in the ColdFusion Administrator. To use cached data, the current query must use the same SQL statement, data source, query name, user name, password, and DBTYPE. Additionally, for native drivers it must have the same DBSERVER and DBNAME (Sybase only).

PROVIDER

Optional. COM provider (OLE-DB only).

PROVIDERDSN

Optional. Data source name for the COM provider (OLE-DB only).

DEBUG

Optional. Used for debugging queries. Specifying this attribute causes the SQL statement actually submitted to the data source and the number of records returned from the query to be output.