DB Scalar
DB Scalar
Section titled “DB Scalar”Type: db-scalar · Package: Database Activities v1.0.0 · Output: object
Executes a SELECT that returns a single value and returns it directly. It is the convenient way to obtain a specific data from the database: a count (COUNT(*)), a maximum (MAX(Fecha)), a total (SUM(Monto)), or the value of a specific cell — without having to manage a DataTable.
How it works
Section titled “How it works”Executes the query and returns the value of the first column of the first row. Uses parameters @nombre and field params for variable values (see parameterized queries).
Required parameters
Section titled “Required parameters”| Parameter | Editor | Description |
|---|---|---|
sql | expression | An SQL statement that returns a single value. Use @nombre for parameters. |
Optional parameters
Section titled “Optional parameters”| Parameter | Editor | Description |
|---|---|---|
session | session | DB Connect session. Within a body it is inherited automatically; outside, pass = db. |
params | JSON | Parameter values, as object { nombre: valor }. |
Output
Section titled “Output”Returns a object with the value (number, text, date…). Convert it if you need with toNumber(...), str(...), etc.
Example
Section titled “Example”Count a customer’s pending orders:
DB Scalar sql = "SELECT COUNT(*) FROM Pedidos WHERE ClienteId = @id AND Estado = 'pendiente'" params = { "id": = clienteId } → output: pendientes
If condition = = toNumber(pendientes) > 0 └─ then: Log message = = "El cliente tiene " + pendientes + " pedidos pendientes"Related activities
Section titled “Related activities”- DB Query — for multi-row results.
- DB Execute — to modify data.