CDS Generic SQL Expressions – CASE expressions ( Simple CASE, Searched CASE & Nested CASE ), COALESCE

0
0

CDS Functions

Generic SQL Expressions

CASE Expressions

3 types of CASE expressions we have that are mentioned below:

Simple CASE Expression

  • The projection list can contain columns that are based on a case differentiation.
  • These columns can be named explicitly
  • It works like normal CASE statement in ABAP.
  • Example: The output is list of columns from table SBUSPART resulting TYPE as customer or Travel Agency based on the TypeCode.

Searched CASE Expression

  • It Operates like an If … elseif construct.

Nested CASE Expression

Example

  • Based on the flight details give priority as follows:
  • Carrid= AA => Priority 1
  • Carrid= LH and connid =400 => Priority 2
  • Carrid= LH and connid=except 400 => Priority 3
  • Carrid = others => Priority Unknown

COALESCE Function

COALESCE( arg1, arg2 ) – returns the value of the argument arg1 (if this is not the null value); otherwise it returns the value of the argument arg2
COALESCE can be used to set reasonable default values for the NULL values

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here