Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Age in Days

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2015-02-24 : 11:29:22
I'm trying to return total Amount for invoices with a date less than or equal to 30 days old.

This is giving me incorrect syntax near 30

SELECT dbo.cicmpy.cmp_name,
sum(CASE WHEN datediff(d,q.date, getdate()) <= 30 then AmountTC else 0 end) as 30Days
FROM dbo.QIVAROpenItems q INNER JOIN
dbo.cicmpy ON dbo.QIVAROpenItems.DebtorNumber = dbo.cicmpy.debnr
group by cicmpy.cmp_name

Ifor
Aged Yak Warrior

700 Posts

Posted - 2015-02-24 : 11:51:15
as [30Days]
Go to Top of Page
   

- Advertisement -