Formula - sqllookup
The sqllookup Formula function looks up the content value in a SQL Server reference table and returns the value of another column from the matching row, for example the area code for a city name.

Animated walkthrough: on the Order Received event of order ORD-10005 in the Order-to-Cash demo, sqllookup takes the ship-to city from the body with jsonPath and returns 08, the area code of Stockholm, from the table AreaCodes. Looking up the customer name instead finds no row: the Test Expression tab shows a warning, The Expression yields no result, not an error.
Prerequisites
- A SQL DB Lookup entry exists: a Name and a Connection String for the reference database, such as
Server=sql01;Database=Directory;Integrated Security=true;TrustServerCertificate=true(see Connection Strings). Add it in the SQL DB Lookup section of the Portal's Infrastructure step (Configure SQL DB Lookup), or provide it with the CLI when you install or update (Run the CLI workflow); the Logging Service gets it as a named connection string. The Name is the firstsqllookupparameter. The Test Expression tab reads the settings on each test, so a new entry needs no restart to test. - The connection string doesn't point to the Nodinite Configuration Database. A lookup through it is refused (Lookups to the Nodinite Configuration Database are not allowed), and an unknown name is an error (No connection string found for key: …).
- The account in the connection string can read the database and table you look up in.
- The network allows access from the Nodinite servers to that SQL Server instance.
Syntax
sqllookup('connectionStringId', 'database', 'table', 'searchColumn', 'resultColumn', content)
Parameters
The parameters are positional; give all six, in this order.
| Parameter | Required | Description |
|---|---|---|
'connectionStringId' |
Yes | The Name of the SQL DB Lookup entry, such as 'SqlDbLookupLocal'. Don't rename an entry that expressions already use. |
'database' |
Yes | The database that holds the reference table. |
'table' |
Yes | The reference table, such as 'AreaCodes'. |
'searchColumn' |
Yes | The column to compare with the content value, such as 'Name'. |
'resultColumn' |
Yes | The column whose value is returned, such as 'AreaCode'. |
content |
Yes | The value to look up: body, context, or the result of another function (see Formula language rules). |
Returns
The resultColumn value of the row whose searchColumn equals the content value. When several rows match, every value is returned. When no row matches, nothing is returned, not an error: the Test Expression tab shows Processed with warning: The Expression yields no result.
Each content value runs one parameterized query, SELECT [resultColumn] FROM [table] WHERE [searchColumn] = @value: the table and column names are quoted as names, and the content value is passed as a parameter.
Examples
All examples use this reference table in the database Directory:
CREATE TABLE dbo.AreaCodes (
Name NVARCHAR(128) NOT NULL,
AreaCode NVARCHAR(8) NOT NULL
);
INSERT INTO dbo.AreaCodes (Name, AreaCode) VALUES ('KARLSTAD', '054'), ('STOCKHOLM', '08');
Example 1: City name in the body to area code
Input
KARLSTAD
Formula
sqllookup('SqlDbLookupLocal', 'Directory', 'AreaCodes', 'Name', 'AreaCode', body)
Result
054
Example 2: City name in a context property to area code
Input
| Key | Value |
|---|---|
| city | STOCKHOLM |
Formula
sqllookup('SqlDbLookupLocal', 'Directory', 'AreaCodes', 'Name', 'AreaCode', context('city'))
Result
08
Notes
- Each evaluation queries SQL Server, during logging and during re-index. Index the search column (for example
CREATE NONCLUSTERED INDEX IX_AreaCodes_Name ON dbo.AreaCodes(Name);) and keep the table compact. - Use a read-only account in the connection string.