首页 > 解决方案 > 在数据库表中显示每个月的最后一个工作日。(工作日不包括周六、周日)

问题描述

我想在数据库表中显示每个月的最后一个工作日(不包括周六、周日)。

标签: sql-servertsql

解决方案


我们使用 pgadmin,我猜它类似于 SQL Server,这是我们使用的查询:

bolReturn = true;

--Get the day of week
SELECT EXTRACT(DOW FROM _start)
Into dayofweek;

--Sataurday
if dayofweek = 6 then
   bolReturn = false;
--Sunday
ELSIF dayofweek = 0 then
bolReturn = false;
end if;

--Check against office closing
select count(*) as start 
into intCount
from tables.officeclosed where closeddate = _start;

if intCount > 0 then
bolReturn = false;
end if;

return 

tables.officeclosed将包含您知道自己休假的日子,例如假期,并且_start是您过去的日期。


推荐阅读