我收到一条错误,指出无法识别等号。我总是在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
可能还有其他任何方法吗?
感谢所有帮助。
答案 0 :(得分: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
它还有一个好处,即查询将自然处理以后引入的新支付类型。