Switch Statement
Use the switch node to create a conditional switch expression. Switch expressions are used to create a conditional execution path to determine which parts of the flow should be executed, based on whether or not values returned match the given input.
- Click here to learn more about switch expressions.
Switch Properties
Display Name
The default display name of the for loop node is SQL Switch 1. Any subsequent for loop nodes are named according to this naming convention, with the appropriate numeric suffix, e.g. 'Switch 2', ' Switch 3', etc.
You can change the Switch node name from directly from this field.
Description
You have the option to add a description to each for loop node; this can be a useful way of documenting the node for yourself and other users.
Switch Expression
Write an expression.
Node Connection Properties
To edit the connection's link value, right click on the connection to open its Properties panel, then choose the required link value. As usual, you can change the 'required status'. You can also add the link value in order to label the link so that you can see what each node represents.
If you have a default option, you can enable the Default Case from it's link:
PQL Expressions
The Pyramid Query Language or PQL (pronounced 'Prequel') is a language built into Pyramid's PYRANA engine to allow users to construct queries that can run against the many SQL data stacks that Pyramid can query natively. PQL includes a vast array of operations and functions that allows users to query data and build analytical logic.
The Master Flow supports the use of the 'Common' PQL functions; when you open the PQL Editor, the Common PQL functions will be exposed, along with any variables that you've created within the flow.
To open the PQL Editor, click the PQL icon from the Switch Expression field.
Switch Expressions
The Switch node supports Switch expressions written in PQL. The Switch function controls the flow of logic by executing certain statements if their 'case' matches the supplied input value. The switch function is most often used to swap out the logic used for building lists based on some changing value in the database.
Switch Syntax
Switch( <Variable> , <Case N> , <Statement N> , OPTIONAL <Default> )
- The variable must be a numeric value.
- The case values (1 to 'n') need to be numeric and are compared to the variable value provided.
-
The last statement is optional and does not need a case value. It will be the default expression if no cases match the variable.
More About Switch Expressions
- Click here to review documentation for the Switch function.
- Click here to learn more about the PQL editor.
- Click here to learn about PQL syntax.
- Click here to learn more about PQL.
Example
In this example, a Case expression was loaded from a variable into the Switch node and used to send out emails:
The Sql node was used to select a given number of rows from the database:
The Set Variable node was used to create a Case statement, sorting rows into groups based on the number of rows passed from the Sql node. The resulting Variable is called 'Group'.
If the number of rows is changed from the Sql node, this will change the rest of the flow. If fewer than 100 rows are selected, the result will be "a". If between 100 and 200 rows are selected, the result will be "b". And if more than 200 rows are selected, the result will be "c". If any other amount of rows is selected, the result will be the default "d".
case( criteria(@NumberOfRows < 100, @NumberOfRows >=100 && @NumberOfRows <200, @NumberOfRows >= 200), criteriaResults("a","b", "c"), "d" )
The 'Group' variable was passed into the Switch node:
Four email nodes were connected to the Switch node, each labeled according to the group into which the rows were sorted.