# Creating a Query from a Text File

Using the CFHTTP Get operation, you can create a query object from a delimited text file. This is a powerful means for processing and handling generated text files. Once the query object is created, it is very simple to reference columns in the query and perform other ColdFusion operations on the data.

Text files are processed in the following manner:

- You specify a delimiter with the DELIMITER attribute. If data in a field includes the delimiter character, it must be quoted or qualified with some other character, which you specify with the TEXTQUALIFIER attribute.
- The first row of a text file is always interpreted as column headings, so that row is skipped. If the first row doesn't contain column headings, you'll need to use the COLUMNS attribute to specify headings so that you don't lose the first row data. You can also use the COLUMNS attribute to specify alternate heading text. Just make sure that you enter an alternate for every column of data in the text file.
- When duplicate column heading names are encountered, ColdFusion adds an underscore character to the duplicate column name to make it unique. For example, if two CustomerID columns are found, the second is renamed "CustomerID_".

| To create a query from a text file:

1. Create a new file in Studio.
2. Modify the file so that it appears as follows:

       <!--- The text file consists of six columns --->
       <!--- separated by commas. --->
       <!--- The rows are --->
       <!--- OrderID,OrderNum,OrderDate --->
       <!--- ShipDate,ShipName,ShipAddress --->
       <!--- This example accepts the first row --->
       <!--- of the text file as the column names --->

       <CFHTTP METHOD="Get"
           URL="http://127.0.0.1/orders/june/orders.txt"
           NAME="juneorders"
           DELIMITER=","
           TEXTQUALIFIER="""">

       <CFOUTPUT QUERY="juneorders">
           OrderID: #OrderID#<BR>
           Order Number: #OrderNum#<BR>
           Order Date: #OrderDate#<BR>
       </CFOUTPUT>

       <!--- You can substitute different column names --->
       <!--- by using the COLUMNS attribute --->

       <CFHTTP METHOD="Get"
           URL="http://127.0.0.1/orders/june/orders.txt"
           NAME="juneorders"

           COLUMNS="ID, Number,Date"
           DELIMITER=","
           TEXTQUALIFIER="""">

       <CFOUTPUT QUERY="juneorders">
           Order ID: #ID#<BR>
           Order Number: #Number#<BR>
           Order Date: #Date#<BR>
       </CFOUTPUT>

3. Substitue the URL with the location of your text file.
4. Substitue the name of a text file and the column headers to those in your text file.
5. Save the file as `querytextfile.cfm` in `myapps` under your Web root directory and view it in your browser.