ColdFusion
  Home arrow ColdFusion arrow Page 3 - Querying SQL 2000 Server from ColdFusion
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COLDFUSION

Querying SQL 2000 Server from ColdFusion
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-02-07

    Table of Contents:
  • Querying SQL 2000 Server from ColdFusion
  • Using ColdFusion data sources to connect to SQL Server 2000
  • Querying pubs database with a ColdFusion query
  • Modifying the query and improving the display

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Querying SQL 2000 Server from ColdFusion - Querying pubs database with a ColdFusion query


    (Page 3 of 4 )

    Sample query implemented

    We will be implementing the following query, which will be run on the MS SQL Server's Query Analyzer tool, in our ColdFusion application:

    The <cfquery/> tag

    ColdFusion application's interaction with databases is through the <cfquery/> tags. The generic <cfquery/> tag is as follows from Macromedia's documentation:

    <cfquery name = "query_name" 
    dataSource = "ds_name" 
    dbtype = "query" 
    username = "username" 
    password = "password" 
    maxRows = "number" 
    blockFactor = "blocksize" 
    timeout = "seconds" 
    cachedAfter = "date" 
    cachedWithin = "timespan" 
    Either of the following: debug = "Yes" or "No" or: 
    debug> 
    SQL statement(s)
    </cfquery>
    

    In this tag, except for the name parameter, everything else is optional, assuming that the data source has been configured with the correct authentication information.

    For starters we will be looking at the simplest query, whose sample run in the query Analyzer was shown above. Using the <cfquery/> tags, the above query can be implemented in ColdFusion as shown in the code that follows. The query has a name, "GetAuthors" and the rows (result set) returned are accessed by GetAuthors.CurrentRow. Of course, the query is run against the source created earlier, CFSQL.

    <cfquery name="GetAuthors" datasource="CFSQL">
    select au_lname, au_fname, phone, city, zip from authors
    order by au_lname
    </cfquery>
    <table>
    <tr>
    <!--Column headers-->
    <td>Last Name</td>
    <td>First Name</td>
    <td>Telephone</td>
    <td>City</td>
    <td>Zip Code</td>
    </tr>
    <!--output of query-->
    <cfoutput query="GetAuthors">
    <tr>
    <td>#GetAuthors.CurrentRow#</td>
    <td>#au_lname#</td>
    <td>#au_fname#</td>
    <td>#phone#</td>
    <td>#city#</td>
    <td>#zip#</td>
    </tr>
    </cfoutput>
    

    When this code is displayed in the web browser, we display the following. You may notice that for the six columns returned, there are only five columns of headers. It is an error that can be corrected by adding another header column, such as "Row number."

     

    More ColdFusion Articles
    More By Jayaram Krishnaswamy


       · We live in a world submerged in data, and accessing data is one of the most...
     

    COLDFUSION ARTICLES

    - Adobe ColdFusion Just Got More RAD
    - How to Access a SQL Anywhere Database with C...
    - CFXML: Probing XMLDOM in ColdFusion
    - Creating a Web Service with ColdFusion: the ...
    - CFAjax: What it is and How to Use it
    - Querying SQL 2000 Server from ColdFusion
    - Introduction to ColdFusion Markup Language, ...
    - Introduction to ColdFusion Markup Language
    - Databases and Dreamweaver MX 2004, concluded
    - Databases and Dreamweaver MX 2004
    - Welcome to Coldfusion MX 6.1, concluded
    - Welcome to Coldfusion MX 6.1
    - What You Must Know About ColdFusion Flow-Con...
    - What You Must Know About Operators in ColdFu...
    - Everything You Must Know About ColdFusion Va...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT