Skip to content
Documentation
Updated 3 minutes to read
Markdown

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.

Look up the area code of an order's ship-to city with sqllookup, animated walkthrough (7.12)
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.

  • 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 first sqllookup parameter. 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.
sqllookup('connectionStringId', 'database', 'table', 'searchColumn', 'resultColumn', content)

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

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.

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

Section titled “Example 1: City name in the body to area code”
KARLSTAD
sqllookup('SqlDbLookupLocal', 'Directory', 'AreaCodes', 'Name', 'AreaCode', body)
054

Example 2: City name in a context property to area code

Section titled “Example 2: City name in a context property to area code”
Key Value
city STOCKHOLM
sqllookup('SqlDbLookupLocal', 'Directory', 'AreaCodes', 'Name', 'AreaCode', context('city'))
08
  • 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.

...

Version:
Release date: N/A
Loading...

Explore Nodinite for 30 days – completely free

  • Find out why this is the leading O&M software
  • Prove your business case
  • Test the self-service for the business side

Loading...

See how Nodinite resolves your technical issues, in a LIVE Demo!

Once you submit this request:

  • We will give you a short call to understand the issues you want to tackle.
  • Understand solutions you have tried and why were you not happy with them.
  • Book a convenient slot for a LIVE demo!

Loading...