简体   繁体   中英

check for valid working days in an SQL function

Im trying to simply create a SQL function in DB2 9.1 (yep thats old). I tried boolean as return value, but the DB Version doesn't support it so i went with integer. The function will just check if the selected day is not on a weekend.

Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=END-OF-STATEMENT;6 
            then return 0;<delim_semicolon>, DRIVER=4.7.85
SQLState:  42601
ErrorCode: -104

what am i doing wrong?

create function checkIfValidWorkingday(variable_date date)
    returns int
    begin atomic
        if dayofweek_iso(variable_date) = 6 
            then return 0;
        else if dayofweek_iso(variable_date) = 7 
            then return 0;
        else return 1;
        end if;
    end
end

Try:

    create function checkIfValidWorkingday(variable_date date)
returns int
language SQL
specific checkIfValidWorkingday
deterministic no external action
   return case when dayofweek_iso(variable_date) between 6 and 7 then 0 else 1 end 

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