4

我收到一条错误消息,提示无法识别等号。我总是在 Access 中测试我的代码以确保它能够正常工作。有谁知道为什么会这样?

代码:

SELECT SUM(
                       IIf(TransactionType = 'Cash', 
                       TotalPrice, 0)
           ) AS TotalCash, 
       SUM(
                       IIf(TransactionType = 'Credit', 
                       TotalPrice, 0)
           ) AS TotalCredit,
       SUM(
                       IIf(TransactionType = 'Check', 
                       TotalPrice, 0)
           ) AS TotalCheck,
       SUM(
                       IIf(TransactionType = 'Multiple', 
                       IIf(MultiCash = 0, 
                        0, MultiCash), 0)
           ) AS MultipleCash,
       SUM(
                       IIf(TransactionType = 'Multiple', 
                       IIf(MultiCredit= 0, 
                        0, MultiCredit), 0)
           ) AS MultipleCredit,
       SUM(
                       IIf(TransactionType = 'Multiple', 
                       IIf(MultiCheck = 0, 
                        0, MultiCheck), 0)
           ) AS MultipleCheck

FROM  RECEIPT 

WHERE ReceiptDate BETWEEN ? AND ?

错误:

Generated SELECT statement.
   Error in list of function arguments: '=' not recongized.
   Unable to parse query text.  

编辑:

让我告诉你我想做什么,而不仅仅是发布代码。这可能是解决此问题的另一个简单方法。所以我想从 vb.net 的报告查看器中提取一份报告,告诉我在特定日期之间使用的投标。

前任。

1/20/2013
Transaction Type                 Amount
Cash                             $100.00
Check                            $300.00
Credit                           $1,000.00
MultiCash                        $1,500.00
MultiCheck                       $1,500.00
MultiCredit                      $1,500.00

报告查看器中的类似内容。用户将能够选择特定日期。我要从中提取信息的 Access 数据库表如下所示。

  RECEIPT
-----------
ReceiptNumber (PK)
ReceiptDate
TotalPrice
TransactionType
MultiCash
MultiCheck
MultiCredit
TotalTax 

也许还有其他方法可以做到这一点?

感谢所有的帮助。

4

1 回答 1

1

像这样的子句:

IIf(MultiCash = 0, 0, MultiCash)

绝对什么都不做。您是在说“如果 multicash 为 0,则使用 0,否则使用该值……”

它看起来像是一种过于复杂的方法。试试这个,它会以稍微不同的格式为您提供数据,但我怀疑它会接近您所追求的

SELECT TransactionType, 
       SUM(TotalPrice)  AS SumTotalPrice,
       SUM(MultiCash )  AS MultipleCash,
       SUM(MultiCredit) AS MultipleCredit,
       SUM(MultiCheck ) AS MultipleCheck
FROM  Receipt 
WHERE ReceiptDate BETWEEN ? AND ?
GROUP BY TransactionType

它还有一个好处是查询自然会处理以后引入的新支付类型。

于 2013-01-24T21:39:04.413 回答