0

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!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
rav007
  • 1
  • Where are your `FROM`s? – Thom A Mar 29 '20 at 15:11
  • We need more context to help with this we can't see the data you are working with (or even the FROM statements that point to it) so we have no idea where ste.TransactionDate is supposed to come from. Please provide a data sample or at least your full code and definition of the data tables. – Simon Notley Mar 29 '20 at 15:23
  • You seem to have used this example: [Count work days between two dates](https://stackoverflow.com/q/252519/6843158) but your implementation is incorrect – Kate Mar 29 '20 at 17:37

0 Answers0