简体   繁体   中英

HANA SQL: CASE WHEN in DO BEGIN ... END statements

Does anyone know, how a CASE WHEN expression can be used in a DO BEGIN... END statement?

Works:

WITH something_to_query_on AS (
SELECT 1 AS first_value, 2 AS second_value FROM dummy
UNION
SELECT 4 AS first_value, 3 AS second_value FROM dummy
)
SELECT first_value, second_value
, CASE WHEN first_value > second_value THEN 1 ELSE 0 END AS first_greater_second
FROM something_to_query_on
;

Works:

DO BEGIN
    something_to_query_on = SELECT 1 AS first_value, 2 AS second_value FROM dummy
                            UNION
                            SELECT 4 AS first_value, 3 AS second_value FROM dummy
                            ;
    
    SELECT first_value, second_value
    /*, CASE WHEN first_value > second_value THEN 1 ELSE 0 END AS first_greater_second*/
    FROM :something_to_query_on
    ;
END

Doesn't work:

DO BEGIN
    something_to_query_on = SELECT 1 AS first_value, 2 AS second_value FROM dummy
                            UNION
                            SELECT 4 AS first_value, 3 AS second_value FROM dummy
                            ;
    
    SELECT first_value, second_value
    , CASE WHEN first_value > second_value THEN 1 ELSE 0 END AS first_greater_second
    FROM :something_to_query_on
    ;
END

Error message:

SQL Error [257] [HY000]: SAP DBTech JDBC: [257] (at 329): sql syntax error: line 10 col 2 (at pos 329)
  SAP DBTech JDBC: [257] (at 329): sql syntax error: line 10 col 2 (at pos 329)

Thank you for your help.

After Reinis Verbelis answer I checked another IDE. Seems the Error only appears with DBeaver but not with HANA Modeler in Eclipse. Will make an issue at their Git Repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM