Sqlserver 生成特地的某天,往前六天的时间,可用于生成生产日期(跳过节假日和周日)

创建节假日表  SysHolidySet


ALTER PROC  [dbo].[GetShouldDate]  @date datetime,@type int ,@hour varchar(10)=null
AS
BEGIN
  if @type=0
  begin
       create table #temp(daysdate varchar(10))
       Declare @i int=1
       while @i<=30
       begin
       Insert into #temp(daysdate)
       values(convert(date,@date-@i))
       Set @i=@i+1

        end
       Delete from #temp where datename(dw,daysdate)='星期日'
       Delete from #temp where daysdate in(select holiday from SysHolidySet)

       select top 6 daysdate,
       case when xh=1 then '前一天'
            when xh=2 then '前两天'
            when xh=3 then '前三天' 
            when xh=4 then '前四天' 
            when xh=5 then '前五天' 
            when xh=6 then '前六天' end as daysname from 
        (select daysdate, ROW_NUMBER()over(order by daysdate desc)xh from #temp)A
   end

drop table #temp

END
 

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值