RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TSQLQuery.SQL Property

Specifies the SQL statement to execute on the database server.

Pascal
property SQL: TWideStrings;
C++
__property TWideStrings SQL;

Use the properties and methods of SQL to specify the query that should be executed on the database server. If SQL is a SELECT statement, the query executes the statement when you call Open or set the Active property to true. If the statement does not return a result set, call the ExecSQL method to execute the statement. 

When you set the SQL property, TSQLQuery checks the statement for parameters and initializes the Params property to reflect any parameters in the statement. You can subsequently use the Params property to adjust the datatype of any parameters and supply values for the parameters. 

At design-time, edit the SQL statement using the property editor that appears when you click the ellipsis button for the property in the Object Inspector. At runtime, use properties and methods of TStrings to clear the current contents, add new contents, or to modify existing contents: 

SQLQuery1.SQL.Clear;

SQLQuery1.SQL.Add('SELECT ' + Edit1.Text + ' FROM ' + Edit2.Text);
if Length(Edit3.Text) <> 0 then

SQLQuery1.SQL.Add('ORDER BY ' + Edit3.Text

SQLQuery1->SQL->Clear();

SQLQuery1->SQL->Add("SELECT " + Edit1->Text + " FROM " + Edit2.Text);
if (!Edit3->Text->IsEmpty())

SQLQuery1->SQL->Add("ORDER BY " + Edit3.Text); 

You can also use the methods of SQL to load a query from a file.

Note: The SQL you supply for this property must be valid for the database server to which the TSQLQuery object is connected.
 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!