INSERT INTO [WHERE] VALUES

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > DDL & DML Statements >

INSERT INTO [WHERE] VALUES

 

The INSERT statement is used to add or append records to tables.

image\tip.gif Use ExecSQL from within in each Apollo interface to execute this statement.

Syntax:

 

INSERT INTO table_reference (columns_list) VALUES (update_expressions)

Example:

INSERT INTO test (last, age, hiredate) VALUES ('Smith', 90, '02/29/2000')

 

The INSERT statement also accepts a subquery as a input data for the insertion. For Example:

INSERT INTO test (last, age, hiredate) (SELECT last, age, hiredate

FROM test WHERE (last = 'Smith') and (age = 90));

 

image\tip.gif Apollo products support ParmsByName and Params methods to allow updating variables. In the following Delphi example, you would also need to define the TApolloQuery.Params property to include the three parameter names and types. Apollo VCL's TApolloQuery example:

ApolloQuery1.SQL.Clear;

ApolloQuery1.SQL.Add('INSERT INTO test (Last, Age, HireDate, Married)');

ApolloQuery1.SQL.Add('VALUES (:Last, :Age, :HireDate, :Married )');

ApolloQuery1.Params[0].AsString := 'Smith';

ApolloQuery1.Params[1].AsInteger := 90;

ApolloQuery1.Params[2].AsDateTime := EncodeDate( 2000, 2, 29 );

ApolloQuery1.Params[3].AsBoolean := True;

 

ApolloQuery1.ExecSQL;

-OR-

ApolloQuery1.SQL.Clear;

ApolloQuery1.SQL.Add('INSERT INTO test (Last, Age, HireDate)');

ApolloQuery1.SQL.Add('VALUES (:Last, :Age, :HireDate)');

ApolloQuery1.ParamsByName('Last').AsString := 'Smith';

ApolloQuery1.ParamsByName('Age').AsInteger := 90;

ApolloQuery1.ParamsByName('HireDate').AsDateTime := EncodeDate( 2000, 2, 29 );

ApolloQuery1.ParamsByName('Married').AsBoolean := True;

ApolloQuery1.ExecSQL;

image\tip.gif After issuing an INSERT command with ExecSQL, the result will not be immediately reflected in any previous result set. Re-issue a SELECT statement to retrieve the new result set.