sql_count Function

Syntax

N sql_count(SQL::Connection cn ,C table ,C expression [,C filter [,SQL::Arguments arguments ]])

Arguments

cnSQL::Connection

An open SQL::Connection to the data source.

tableCharacter

The table to query.

expressionCharacter

Defines the data retrieved from the table. Use "*" to specify all fields. This expression typically matches the expression used to retrieve data from the data source. If the expression does not affect the number of records returned by the database, you can use a simple expression such as "*" when getting the record count.

filterCharacter

An optional filter expression.

argumentsSQL::Arguments

Default = null_value(). Defines the arguments used in the filter expression.

Returns

countNumeric

Returns a count of the number of records returned from the data source by the SQL expression. Returns -999999999999 if an error occurs. If running on the Application Server, an error message will be logged to the Xbasic error log with information about the error. If running in a desktop environment, the error message details will be shown in a popup window.

Description

Returns the count of 'expression' for a SQL table.

dim cn as sql::Connection
cn.open("::Name::northwind")

? sql_count(cn,"customers","*","country='UK'")
= 7

? sql_count(cn,"customers","ContactTitle","country='UK'")
= 7

Notice that the field we are specify for the expression argument is irrelevant. Specifying * or ContactTitle returns the same value. The filter expression has more effect on the record count than the expression. For example:

? sql_count(cn,"customers","*","country='USA'")
= 12