Skip to Content

SAP HANA XSA SQL Expression WHEN CASE for entity .hdbcds

Hi,

is this possible to set the current date and current time statement for each new record in the table, if I use this case sql expression in the table?

At this moment it works only for all the rows, which is not what I want.

    entity Patient {
        key PatientID      : Integer    not null;
            ID: String(64) not null; // GUID32 SYSUUID
            AnmeldeDatum   : LocalDate  =
            case
                when ID <> NULL then current_date
            end;
            
            AnmeldeZeit    : LocalTime  =
            case
                when ID <> NULL then current_time
            end;

Thanks for helping us!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 06 at 12:21 PM

    I'm not sure if I got your question right? You wanna set for each new inserted record the current date and current date in the corresponding columns? Why you are not just define a default value for your columns ( ... AnmeldeDatum: LocalDate default current_date; AnmeldeZeit: LocalTime default current_time ...)?

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 10 at 10:44 AM
    -1

    Hope the cursor function will works with the Function current date and current time.

    CREATE PROCEDURE "<SCHEMA_NAME>"."CURSOR_EXAMPLE" (
    IN ip_rate DECIMAL(15,2),
    OUT ex_products "<SCHEMA_NAME>"."TT_PRODUCT_ DETAILS")
    LANGUAGE SQLSCRIPT
    SQL SECURITY INVOKER
    AS
    BEGIN
    /*****************************
    Write your procedure logic
    *****************************/
    DECLARE v_new_price DECIMAL(15,2);
    DECLARE CURSOR c_products FOR
    SELECT PRODUCT_ID, PRODUCT_NAME, PRICE
    FROM "<SCHEMA_NAME>"."PRODUCT_DETAILS";
    FOR cur_row as c_products DO
    v_new_price := cur_row.PRICE + (cur_row.PRICE * :ip_rate);
    UPDATE "<SCHEMA_NAME>"."PRODUCT_DETAILS"
    SET PRICE = v_new_price where PRODUCT_ID = cur_row.PRODUCT_ID;
    END FOR;
    ex_products = select PRODUCT_ID, PRODUCT_NAME, PRICE
    FROM "<SCHEMA_NAME>"."PRODUCT_DETAILS" ;
    END;

    we need to update the sales price of each record. We will pass the increased rate and use a cursor to update each record.

    Not sure, on the above just a thought came to mind..
    Add comment
    10|10000 characters needed characters exceeded