AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomConnection.ExecSQLScalar Method (String, array of Variant, array of TFieldType)

Executes a SQL command with parameters and fetches a single value.

Group
Links
Parameters 
Description 
const ASQL: String 
A SQL command to execute. 
const AParams: array of Variant 
An open array of parameter values. 
const ATypes: array of TFieldType 
An open array of parameter data typesd. 

The value of first column in first row of first result set.

The ExecSQLScalar method executes a SQL command with parameters. The method returns a value of first column in first row of first result set. All other cursors will be discarded. 

The method allows to explicitly specify parameter types. If type of some parameter is not needed to be specified, then corresponding item in ATypes must be ftUnknown.

function ExecSQLScalar(const ASQL: String; const AParams: array of Variant; const ATypes: array of TFieldType): Variant; overload;
var
  sName: String;
...
  sName := ADConnection1.ExecSQLScalar('select name from {id Employees} where id = :id', [100], [ftLargeInt]);
What do you think about this topic? Send feedback!