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

Using SUM with CASE, SQL

$
0
0

Hi,

Another question for you all :). I've tried to explain as best I can....

I am preparing a 'debt' list to show which of our clients owe us money. I can then schedule this for delivery to our accounts team each Monday Morning....

The amount the clients owe is a sum of a field called DT.transactbalance. I am easily able to sum this and group it by client name.

What I would like to do now is prepare that debt list in distinct columns based on how "old" the debt, is based on the date it was due (field DT.transacteffdate).

So: -

if DT.Transacteffdate between today and 20 days ago then I need a sum of transactbalance in a column called "Up to 20" - if the client has nothing in that date range I can simply show '0.00'

If DT.transacteffdate is between 21-30 days old, a sum of DT.transactbalance is needed in 21-30" else 0.00

If DT.transacteffdate...


Viewing all articles
Browse latest Browse all 4871

Trending Articles