Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Issue with differences between dates - SQL

$
0
0

Hi,

Can anyone spot what I am obviously doing wrong here? I'll probably explain it badly, but..

I am using a case function to determine a date to use later in my statement. I am calling this 'Accounting Date'...

case when DT.TransactDate DT.TransactEffDate then DT.TransactDate else DT.TransactEffDate end [Accounting Date],

(both TransactDate and TransactEffDate are of type datetime).

Then I am using additional case functions to display a chosen figure in a column, depending on the difference between the Accounting Date, and today's date: -

sum (case when 'Accounting Date' getdate()-20 then DT.TransactBalance else 0 end) as 'Less Than 20 Days',

sum (case when 'Accounting Date' getdate()-30 and 'Accounting Date' < getdate()-20 then DT.transactbalance else 0 end) as 'Between 21 and 30',

However when I execute this, I get the following error: -

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date...

< getdate()-20 then DT.transactbalance else 0 end) as 'Between 21 and 30',

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>