title: CASE Statement in HANA Studio
body: <p>I am trying to implement a CASE statement in my Caculation View in HANA Studio. This is for creating a Calculated Column. The following is what I am trying to accomplish. There are five delivery statuses and for each there are three possible values (A,B or C). The combination of each of these will results in a certain status, which I want to incorporate in code in my Caculation View.</p>
  <p>This is the SQL statement I want in my Calculated Column in HANA Studio:</p>
  <pre><code>CASE WHEN WBSTK = 'A'
  THEN CASE WHEN KOQUK = 'A' AND LVSTK = 'A' AND PKSTK = 'A' AND 
                 KOSTK = 'A' THEN 'Not Processed'
  WHEN KOQUK = 'A' AND PKSTK = 'A' AND LVSTK = 'B' AND 
                 KOSTK = 'C' THEN 'Printed'  
  WHEN KOQUK = 'B' AND LVSTK = 'B' AND PKSTK = 'A' AND 
                 KOSTK = 'Ç' THEN 'Partially processed'
  WHEN KOQUK = 'C' AND PKSTK = 'A' AND LVSTK = 'C' AND
                 KOSTK = 'C' THEN 'Processed' 
  WHEN KOQUK = 'C' AND PKSTK = 'C' AND LVSTK = 'C' AND 
                 KOSTK = 'C' THEN 'Ready for shipping'
  END
  END
  </code></pre>
  <p>This is the code I have which works in Microsoft SQL Server Management Studio:</p>
  <pre><code>SELECT [status of pick confirmation] AS KOQUK,
         [Total goods movement status] AS WBSTK,
         [Overall status of warehouse management activities] AS LVSTK,
         [Overall packing status of all items] AS PKSTK,
         [Overall picking / putaway status] AS KOSTK,
  
  CASE WHEN [Total goods movement status] = 'A'
  THEN CASE WHEN [Status of pick confirmation] = 'A' AND [Overall status of warehouse management activities] = 'A' AND [Overall packing status of all items] = 'A' AND 
                 [Overall picking / putaway status] = 'A' THEN 'Not Processed'
  WHEN [Status of pick confirmation] = 'A' AND [Overall packing status of all items] = 'A' AND [Overall status of warehouse management activities] = 'B' AND 
                 [Overall picking / putaway status] = 'C' THEN 'Printed'  
  WHEN [Status of pick confirmation] = 'B' AND [Overall status of warehouse management activities] = 'B' AND [Overall packing status of all items] = 'A' AND 
                 [Overall picking / putaway status] = 'Ç' THEN 'Partially processed'
  WHEN [Status of pick confirmation] = 'C' AND [Overall packing status of all items] = 'A' AND [Overall status of warehouse management activities] = 'C' AND
                 [Overall picking / putaway status] = 'C' THEN 'Processed' 
  WHEN [Status of pick confirmation] = 'C' AND [Overall packing status of all items] = 'C' AND [Overall status of warehouse management activities] = 'C' AND 
                 [Overall picking / putaway status] = 'C' THEN 'Ready for shipping'
  END
  
  END AS 'Delivery Status'
  
  FROM VBUK
  </code></pre>
  <p>When trying to add this in HANA Studio I get the following error:</p>
  <blockquote>
  <p>Invalid Expression SAP DBTech JDBC: [2048]: column store error: failed
  to set expression: [6968] Evaluator: syntax error in expression
  string;expected TK_LPAREN,u... And this is followed by the above CASE
  Statement</p>
  </blockquote>
  <p>Also the WHEN in line 1 and the THEN in line 3 are red underlined.</p>
  <p>I am not sure what I am doing wrong. Anyone has an idea? These are fields from the VBUK table in SAP.</p>
  <p>Thanks in advance!</p>