Case predicate
When you use the case predicate, you can include case statements in the SQL that you build in the expression editor.
The case option on the expression editor enables you to include case statements in the SQL you are building. You can build case statements with the following syntax.
CASE WHEN condition THEN value
CASE WHEN...
ELSE value
or
CASE subject
WHEN match_value THEN value
WHEN...
ELSE value
The expression editor
when you have selected the Case predicate contains these fields:
- Case Expression. This is the subject of the case statement. Specify this if you are using the second syntax described above (CASE subject WHEN). By default, the field offers a choice of the columns from the table or tables you have dragged to the table selection canvas. To choose an alternative, click the browse button next to the field. This gives you a choice of data types, or of specifying another expression, a function, or a job parameter.
- When. This allows you to specify a condition or match value for your case statement. By default, the field offers a choice of the columns from the table or tables you have dragged to the table selection canvas. To choose an alternative, click the browse button next to the field. This gives you a choice of data types, or of specifying another expression, a function, or a job parameter. You can access the main expression editor by choose case expression editor from the menu. This allows you to specify expressions such as comparisons. You would typically use this in the first syntax example. For example, you would specify grade=3 as the condition in the expression WHEN grade=3 THEN 'first class'.
- Then. Use this to specify the value part of the case expression. By default, the field offers a choice of the columns from the table or tables you have dragged to the table selection canvas. To choose an alternative, click the browse button next to the field. This gives you a choice of data types, or of specifying another expression, a function, or a job parameter.
- Add. Click this to add a case expression to the query. This clears the When and Then fields so that you can specify another case expression.
- Else Expression. Use this to specify the value for the optional ELSE part of the case expression.