BuildSelect

(ODBC Manager Library)

Description: Builds SQL selection queries using supplied field names and values. Made to be called as a subroutine only.
Returns: Text (the SQL query)
Usage: Script Only.
Related to: AddConnection | BuildDelete | BuildInsert | BuildUpdate | ConvertToDbDate | ConvertToDbTime | ConvertToDbTimeStamp | ConvertToVTSDate | ConvertToVTSTime | ConvertToVTSTimeStamp | CopyRecords | DBDropList | DBGridList | ErrMessage | ExecuteQuery | ExecuteQueryCachedFlushCache | FormatBatchQuery | GetConnList | ResultFormat | StatsWin | TableSynch | Transaction | TransactionCached
Format: \ODBCManager.BuildSelect( SelectFields,  TableName,  WhereFields,  WhereOperators,  WhereValues,  WhereSQLDataTypes,  WhereAND,  OrderFields,  Qualifier)
Parameters:  
SelectFields
Required. Text array of field Names to read
TableName
Required. May be a simple value or a one-dimensional array. The name(s) of the table(s) that will be queried.
WhereFields
Required. May be a simple value or a one-dimensional array. Field names for WHERE clause
WhereOperators
Required. May be a simple value or a one-dimensional array. Operators for WHERE clause
WhereValues
Required. Any SQL data type. May be a simple value or a one-dimensional array. Values for WHERE clause
WhereSQLDataTypes
Required. Values indicating the data type of the insert values. Should be a simple value or an array matching the WhereFields parameter.

Refer to Data Type Codes used in the ODBC Manager for a list of the codes.
WhereAND
Required. Can be any expression that evaluates to a Boolean true or false.
If set to true (non-zero) then the components of the WHERE clauses are to be ANDed together.
If false (0) an OR is used between the sub clauses.
OrderFields
Required. May be a simple value or a one-dimensional array. Provides the field names for ORDER BY clause
Qualifier
Required. SQL Qualifier such as "top 100", "unique", etc

Comments:

This module is a member of the ODBCManager Library, and must therefore be prefaced by \ODBCManager, as shown in "Format" above.

Example:

CheckRecord[
  If 1 CheckIfExists;
  [
    { Build select query to check if a specified tag/variable exists }

    WhereFields[0] = "TagName";
    WhereFields[1] = "TagVariable";
    WhereOperators[0] = "=";
    WhereOperators[1] = "=";
    WhereValues[0] = TagName;
    WhereValues[1] = TagVariable;
    WhereSQLDataTypes[0] = \ODBCManager\#SQL_VARCHAR;
    WhereSQLDataTypes[1] = \ODBCManager\#SQL_VARCHAR;

    GetTagIDQuery = \ODBCManager\BuildSelect("ID", TagIDTableName,
                                           &WhereFields, &WhereOperators, &WhereValues, &WhereSQLDataTypes, 1);
    { Execute Query }
    LocExecQueryErr = Invalid();
    \ODBCManager\ExecuteQuery(&LocExecQueryErr, GetTagIDQuery, LoggerDSN,
                            Invalid, Invalid, &RawODBCData, &LocODBCAttribPtr,
                            &LocODBCErrMsgPtr, &LocODBCSQLStateErr, &LocODBCError,
                            1 { format into [Row][Field] });
  ]
]

CheckIfExists[...