Don't know how to do that
Plus, for this, really unnecessary I think
Since any data you have that contains dates is all that's needed here to test the codes.
Any sample data with a few dates of the following is all that's needed to test the date filters
CASE WHEN { fn DAYOFWEEK(dbo.SO_SalesOrderHistoryHeader.OrderDate) } IN (1 , 7) THEN dbo.DAYSADDNOWK(OrderDate , 1) ELSE DATEADD(dd , 0 , DATEDIFF(dd , 0 , dbo.SO_SalesOrderHistoryHeader.OrderDate)) END As BizDate
Using your sample data (corrected to syntax that works):
create table #SO_SalesOrderHeader(OrderDate Date);
insert into #SO_SalesOrderHeader
Values ('2018-05-01'),('2018-05-02'),('2018-05-03'),('2018-05-04'),('2018-05-04'),('2018-05-06'),('2018-05-07');
This:
select orderdate
,datename(weekday,orderdate) as dayname
from #so_salesorderheader
where orderdate>=dateadd(day
,case datepart(weekday,current_timestamp)
when 1 then -4
when 5 then -3
when 6 then -3
when 7 then -3
else -5
end
,cast(current_timestamp as date)
)
and orderdate<cast(current_timestamp as date)
;
select orderdate
,datename(weekday,orderdate) as dayname
from #so_salesorderheader
where orderdate>=dateadd(day
,case datepart(weekday,current_timestamp)
when 1 then -4
when 5 then -3
when 6 then -3
when 7 then -3
else -5
end
,cast(current_timestamp as date)
)
and orderdate<cast(current_timestamp as date)
and datepart(weekday,orderdate) not in (1,7)
;
select orderdate
,datename(weekday,orderdate) as dayname
from #so_salesorderheader
where orderdate>=dateadd(day
,case datepart(weekday,current_timestamp)
when 1 then -6
when 7 then -5
else -7
end
,cast(current_timestamp as date)
)
and orderdate<cast(current_timestamp as date)
and datepart(weekday,orderdate) not in (1,7)
;