简体   繁体   English

在SQL函数中检查有效的工作日

[英]check for valid working days in an SQL function

Im trying to simply create a SQL function in DB2 9.1 (yep thats old). 我试图在DB2 9.1中简单地创建一个SQL函数(是那么旧)。 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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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