Creating an Insert Page with CFQUERY  
 
 

For more complex inserts from a form submittal you can use a SQL INSERT statement in a CFQUERY tag instead of a CFINSERT tag. The SQL INSERT statement is more flexible because you can insert information selectively or use functions within the statement.

 
 
  Basic SQL syntax  
 
 

The syntax for a basic SQL insert statement is:

INSERT INTO tablename (columnnames)
VALUES (values)

The VALUES keyword specifies the values for the columns in the new row. You have to type the values you want to add in the same order as the columns in the columnnames section of the statement.

 
 
  Example: CFQUERY insert  
 

To insert the form data from the example above with a CFQUERY use this syntax:

<CFQUERY NAME="AddEmployee" 
    DATASOURCE="Employee DB">
    INSERT INTO Employees (FirstName, LastName, Phone)
    VALUES ('#Form.FirstName#', '#Form.LastName#', 
    '#Form.Phone#')
</CFQUERY>


 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.