Skip to content

Example of custom script using a stored procedure

This example shows a stored procedure written to read data in pages or windows.

CREATE PROCEDURE [bm20Load].[USP_OperationExecutionPropertyStaticValueSelect]
@ChunkSize AS [int],
@PageNumber AS [int],
@RowFrom AS [datetime],
@RowTo AS [datetime]
AS
BEGIN
SELECT 
CAST(MyOperationExecutionPropertyStaticValueSiteId AS smallint) AS [OperationExecutionPropertyStaticValueSiteId],
CAST(MyOperationExecutionPropertyStaticValueKey AS nvarchar(255)) AS [OperationExecutionPropertyStaticValueKey],
CAST(MyOperationExecutionPropertyKey AS nvarchar(255)) AS [OperationExecutionPropertyKey],
CAST(MyOperationExecutionPropertySiteId AS smallint) AS [OperationExecutionPropertySiteId],
CAST(MyOperationExecutionSiteId AS smallint) AS [OperationExecutionSiteId],
CAST(MyOperationExecutionKey AS nvarchar(255)) AS [OperationExecutionKey],
CAST(NULL AS datetime) AS [DatetimeValue],
CAST(NULL AS float) AS [FloatValue],
CAST(0 AS smallint) AS [Sequence],
CAST(MyStringValue AS nvarchar(255)) AS [StringValue],
CAST(MyRowInserted AS datetime) AS [RowInserted],
CAST(MyRowUpdated AS datetime) AS [RowUpdated]
FROM mySchema.MyTable
WHERE (ISNULL(MyRowUpdated, MyRowInserted) >= @RowFrom AND ISNULL(MyRowUpdated, MyRowInserted) < @RowTo)
ORDER BY MyOperationExecutionPropertyStaticValueKey
OFFSET @ChunkSize * (@PageNumber - 1) ROWS FETCH NEXT @ChunkSize ROWS ONLY
option (recompile)
END

Important recommendations

  • If the "Smart Time Window Enabled" checkbox was selected when editing the database, the RowInserted and RowUpdated columns are mandatory. If you do not include them in the script, the flows to load data are not completed correctly.
  • The WHERE condition must include a filter on the time interval using the RowFrom and RowTo parameters as shown in the example.
  • MyRowInserted and MyRowUpdated must be expressed in UTC time.
  • The ORDER BY and OFFSET/FETCH instructions allow you to execute a paged load and must not be modified.
  • You must not modify the schema, the name or the parameters of the stored procedure.
  • The FROM clause can be more complex (JOIN, GROUP etc.)
  • The first two columns represent the natural key. They must therefore be unique.
  • If the source is a product of the Operation Execution Core family, it is recommended that you use the CEPSCHEMA CEPDB tags instead of the real database names. If you use these tags, the system applies the names used in the environment.

Last update: October 26, 2026