Skip to content

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.

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).

ParameterEditorDescription
sqlexpressionAn SQL statement that returns a single value. Use @nombre for parameters.
ParameterEditorDescription
sessionsessionDB Connect session. Within a body it is inherited automatically; outside, pass = db.
paramsJSONParameter values, as object { nombre: valor }.

Returns a object with the value (number, text, date…). Convert it if you need with toNumber(...), str(...), etc.

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"