SELECT Name,
SUM(IIf([Date] = DateAdd('d', - 7, DATE ()), PBal,0)) AS Opening,
SUM(IIf([Date] = DateAdd('d', - 7, DATE ()), NetAmount,0) ) AS DAY1,
sum(IIf([Date] =DateAdd('d',-6,Date()),NetAmount ,0))AS DAY2,
sum(IIf([Date] =DateAdd('d',-5,Date()),NetAmount ,0))AS DAY3,
sum(IIf([Date] =DateAdd('d',-4,Date()),NetAmount,0 ))AS DAY4,
sum(IIf([Date] =DateAdd('d',-3,Date()),NetAmount,0 ))AS DAY5,
sum(IIf([Date] =DateAdd('d',-2,Date()),NetAmount,0 ))AS DAY6,
sum(IIf([Date] =DateAdd('d',-1,Date()),NetAmount,0 ))AS DAY7,
(Day1+Day2+Day3+Day4+Day5+Day6+Day7) AS Billtotal,
sum(IIf([Date] =DateAdd('d',-7,Date()),(NetAmount-BBal),0)) AS Cash1,
sum(IIf([Date] =DateAdd('d',-6,Date()),(NetAmount-BBal),0)) AS Cash2,
sum(IIf([Date] =DateAdd('d',-5,Date()),(NetAmount-BBal),0)) AS Cash3,
sum(IIf([Date] =DateAdd('d',-4,Date()),(NetAmount-BBal),0)) AS Cash4,
sum(IIf([Date] =DateAdd('d',-3,Date()),(NetAmount-BBal),0)) AS Cash5,
sum(IIf([Date] =DateAdd('d',-2,Date()),(NetAmount-BBal),0)) AS Cash6,
sum(IIf([Date] =DateAdd('d',-1,Date()),(NetAmount-BBal),0)) AS Cash7,
Cash1+Cash2+Cash3+Cash4+Cash5+Cash6 +Cash7) as CashPaid,
(Billtotal-CashPaid) + Opening AS Currentbalance
FROM Customer
GROUP BY Name
答案 0 :(得分:2)
Date()
不是函数。你想要GetDate()
dateadd
中的第一个参数不带引号:dateadd(d, -4, getdate())
IIF
不是函数。您可能会在pivot
上找到datediff
提供更简单的查询。