I am trying to find the difference between two dates in SQL but ignoring weekends...
I've tried looking at other answers and keep getting the error:
Msg 4104, Level 16, State 1, Line 7
The multi-part identifier "ste.TransactionDate" could not be bound.
My current code is:
DATEDIFF(WEEKDAY, ste.TransactionDate, ste.SettlementDate) AS DaysToCSD,
and I did change this to
DECLARE @d1 datetime, @d2 datetime
SELECT @d1 = ste.TransactionDate, @d2 = ste.SettlementDate
SELECT DATEDIFF(dd, @d1, @d2) - (DATEDIFF(wk, @d1, @d2) * 2) -
CASE WHEN DATEPART(dw, @d1) = 1 THEN 1 ELSE 0 END +
CASE WHEN DATEPART(dw, @d2) = 1 THEN 1 ELSE 0 END
I am not great at SQL..not a dev...so any help appreciated!