Question

I'm working on DB2 stored procedure, which will be called by the Korn Shell (.ksh). My DB2 version is 11.5 and it is running on AIX.

I was stuck in TIMESTAMP to DATE conversion. Below is my requirement.

If s_day < day(s_date) then
start_date = YYYY-MM from s_date + 1 day from s_day 
end if

Note here s_date is DATE variable, s_day is CHAR variable and start_date is DATE variable.

So I tried, the following code, but got an error.

   IF s_day < DAY(s_date) 
    THEN
    SET start_date = DATE (DATE(s_date,'YYYY-MM') || s_day + 1);
    END IF

Sample values

s_day =03
s_date= 15/05/2020
expected output start_date is 2020-05-04

Can anyone help me to achieve expected output?

No correct solution

OTHER TIPS

Try

IF int(s_day) < DAY(s_date) 
THEN
    SET start_date = THIS_MONTH(s_date) + int(s_day) days;
END IF
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top