IF
Overview
The IF operation allows you to use computed conditions in order to selectively start a pipeline block.
The IF operation is not supported before the first SELECT or LOAD operation.
The condition provided must be relatively simple and operates best on row-level operations. This in-memory operation follows the .NET DataTable.Compute() specification.
Syntax
Executes an SQL CDC block conditionally; may contain within an APPLY PIPELINE operation.
IF (...)
BEGIN
{ ... }
END
{
[
ELSE IF (...)
BEGIN
{ ... }
END
]
}
{
ELSE
BEGIN
{ ... }
END
}
;CONDITION |
The condition to evaluate as a simple SQL-like operation |
Example 1
DECLARE PARAM @p = '1';
-- Get data from an RSS Feed
SELECT * FROM HTTP [Rss Feed] (GET /econi.xml) APPLY TX (//item);
IF ({{@p}} = 1)
BEGIN
SELECT * FROM HTTP [Rss Feed] (GET /budget.xml) APPLY TX (//item);
END
Example 2
-- Declare a parameter
DECLARE PARAM @p = 'budget';
-- Get data from an RSS Feed
SELECT * FROM DB [sql2022] (SELECT GETDATE() as [now]);
IF ('{{@p}}' = 'budget')
BEGIN
SELECT * FROM HTTP [Rss Feed] (GET /budget.xml) APPLY TX (//item);
END
ELSE IF ('{{@p}}' = 'economic')
BEGIN
SELECT * FROM HTTP [Rss Feed] (GET /econi.xml) APPLY TX (//item);
END
ELSE
BEGIN
EXIT;
END