How to exclude weekends and holidays in a query I have been tasked with creating a flat file. One of the fields that I need is a date field. I need the disco date to be LAST_EVENT_PROC_DT + 12 unless that date falls on a weekend or holiday,if so the disco date would be the next business day. This date field is stored in my system as a Numeric field. I am trying to write it is a case statement using our holiday table and some weekend exclusion code.
This is the column I am trying to query:

LAST_EVENT_PROC_DT (numeric(8,0),not null)


It holds a date formatted like: 20150506

This is the flat file output:

'' + '|' +
'' + '|' +
cast(q.NEXT_EVENT_PROC_DT as varchar) + '|' + -- Due Date
cast(q.LAST_EVENT_PROC_DT +12 as varchar) + '|' + -- Disco Date = Due date +15
CONVERT(VARCHAR(10),GETDATE() +15,112) + '|' + -- Agency Send Date todays date + 15


I am using SQL Server 2014
You Can simply use datediff function of sql. and then you can subtract weekends between those dates if any.Here Sunday is set as a firstday of week, For example check below query. 

Declare @startdatee as DateTime
Declare @enddatee as DateTime
Set @startdatee = GETDATE();
set @enddatee = GETDATE()+1;
select @startdatee,@enddatee,(datediff(day,@startdatee,@enddatee+1)-(2)*datediff(week,@startdatee,@enddatee))


And If You want to exclude holiday's too, then, You also can calculate holidays between start/end date and can subtract that from final selection.
i gave you example here.
You can use your holiday's table,here i am just using temp table for example.

Declare @holidays Table (ID int,Name Varchar(50),[Date] date)
Insert into @holidays VALUES 
(1,'holiday1','2018-07-07'),
(2,'holiday2','2018-07-12')

Declare 
    @startdate datetime = '2018-07-02',
    @enddate datetime =  '2018-07-30',
    @holiday int = 0

    Set @holiday = (Select COUNT(*) FROM @holidays WHERE (Date BETWEEN @startdate AND @enddate) 
                    AND DATEPART(Weekday,Date) not in (1,7)
                    )

SELECT
   (DATEDIFF(dd, @StartDate, @EndDate) + 1)
  -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
  -(case datepart(dw, @StartDate) when 1 then 1 else 0 end) 
  -(case datepart(dw, @EndDate) when 7 then 1 else 0 end)
  -@holiday