Search code examples
hanasapb1hana-studio

HANA DB : How to use CONCAT syntax more than 2 fields


I'm using query in HANA Studio , It's work

 CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT
 (T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2")) ELSE T7."SlpName" END
 AS"Sales Emp",

But I want to CONCAT more fields

**For Example :**  CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT (T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2"),**CONCAT
 ('+',T0."U_XXX_SalEmp3"**),**CONCAT ('+',T0."U_XXX_SalEmp4"**)) ELSE
 T7."SlpName" END  AS"Sales Emp",

Solution

  • You can use the two pipe symbols || for chained concatenation.

    Your example would look like this:

    CASE 
     WHEN T0."U_ISS_SalEmp2" is not null 
          THEN 
              T7."SlpName" || '+' || 
              T0."U_ISS_SalEmp2" || '+' ||
              T0."U_ISS_SalEmp3" || '+' ||
              T0."U_ISS_SalEmp4"
     ELSE
             T7."SlpName" 
    END         AS "Sales Emp"