MS Access Query出现问题

时间:2011-01-18 08:17:00

标签: c# ms-access-2007

我正在使用MS Access 2007和C#应用程序。以下是我目前正在使用的查询。此查询工作正常:

string qry = "Select sum(InvoiceAmount) as InvAmt, InvoiceDate From Invoices Group By InvoiceDate Having (InvoiceDate between #"+previousPaymentDate+"# and #"+currentPayDate+"#)";

上述查询将按发票日期返回发票金额组合。

由于支票退回而产生了一些发票。即25000 / - 是检查反弹的发票金额。我使用“ChequeBounced”布尔字段标记了此发票。有没有办法在上面的查询中包含此子句。我希望这个查询有点像这样 -

 string qry = "Select sum(InvoiceAmount) as InvAmt, InvoiceDate From Invoices Group By InvoiceDate Having (InvoiceDate between #"+previousPaymentDate+"# and #"+currentPayDate+"#) and ChequeBounced='False'";

感谢您分享您的时间。

1 个答案:

答案 0 :(得分:2)

怎么样:

SELECT InvoiceDate, Sum(InvoiceAmount) AS InvAmount
FROM Invoices
WHERE ChequeBounced=False
GROUP BY InvoiceDate
HAVING (InvoiceDate between #"+previousPaymentDate+"# and #"+currentPayDate+"#)

为清楚起见,我没有用引号括起SQL。请注意,False是Access中的内置常量,等于零,不应为boolean字段引用。最好确保您的日期格式为yyyy / mm / dd,否则您可能会得到意想不到的结果。