sql server - Using Case When Then to Filter Dates -


i need create view accounts team show aged debtors via excel.

i've got due dates of outstanding invoices , want achieve 30,60,90 , 120 day breakdown.

my current script this...

case when st_transmonth = month(getdate())       '30 days'       else if st_transmonth = month(getdate()) + 30 = '60 days' , on.  

i can't ge work though, appreciated!

your math has subtle flaw in it, in you're using month check length of days transaction date, know, not months have 30 days, therefore you're going introduce areas discrepancy, potentially involve legal issues if send late notices people when they're not technically late.

furthermore, more 30 days passed due, you're not catching because it's different month, example, bought on 25th of last month , it's 31st of month now, they're > 30 days passed due, you're not reporting it.

instead of month, use datediff command, part of tsql. allows get difference between 2 dates specified unit:

case     when st_transmonth > dateadd(dd, -30, getdate()) '30 days'     when st_transmonth > dateadd(dd, -60, getdate()) '60 days'     -- add more cases needed end 

give try instead.

good luck.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -