I need to calculate the number of weekdays between a StartDate and EndDate. I use the following which works fine but my StartDate needs to be the 'TradeDate' in the table, and not a specific date set for the StartDate. How can I change the 'SET @StartDate' correctly to pick the 'TradeDate' for each record in the table?
Declare @StartDate DATEtime
Declare @EndDate DATEtime
@StartDate = ? ? ?
@EndDate = GETDATE()
(DATEDIFF(dd, @StartDate, @EndDate) -1) -(DATEDIFF(wk, @StartDate, @EndDate) * 2) -(
CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END
CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END
) as DaysOutstanding,
StatusId = '1'
and Type = '0'