I have the following query running against a Sybase database which is intended to select the two previous business days; ignoring weekends (we don't care about holidays). The query works, apart from on mondays, in which the query only returns the date for the previous friday - running the query on a tuesday works, returning monday and the previous friday. I've been staring at it all day and can't work out why; can anybody help? Unfortunately in this situation I am unable to use a calendar table.
SELECT dateadd(dd, CASE DATEPART(dw, getdate())
WHEN 1 THEN -2
WHEN 2 THEN -3 ELSE -1
END, CONVERT (VARCHAR (10), dateadd(day, 0 getdate()), 102)), (SELECT dateadd(dd, CASE DATEPART(dw, CONVERT (VARCHAR (10), dateadd(day, -1, getdate()), 102))
WHEN 1 THEN -2
WHEN 2 THEN -3 ELSE -1
END, CONVERT (VARCHAR (10), dateadd(day, -1, getdate()), 102)))
Any assistance would be greatly appreciated!