0

此查询运行项目分类帐。当我尝试使用 =SUM([Returns]) 对访问报告上的返回字段求和时,即返回是访问报告上的文本框。运行报告时显示以下错误。**

此表达式键入不正确,或者它太复杂而无法计算。例如,一个数值表达式可能包含太多复杂的元素。尝试通过将表达式的一部分分配给变量来简化表达式。

**

SELECT ITEM, [Transaction Date], ID, Reciept, Issued, Returns, Remarks, Manual
FROM 
 (SELECT t.item AS ITEM, irh.reciept_date AS [Transaction Date], ird.inv_id AS ID, ird.inv_qyt AS Reciept, Null AS Issued, NULL AS Returns, ird.remarks AS Remarks, ird.inv_manual_number AS Manual
FROM inventory_reciepts_header AS irh, inventory_reciepts_detail AS ird, inventory AS t
WHERE 
ird.inv_id=t.id 
AND ird.reciept_header_id=irh.id
UNION ALL

 SELECT t.item AS ITEM, iih.issue_date As  [Transaction Date], iid.inventory_id AS ID,NULL AS Reciept, iid.inventory_qyt AS Issued, NULL AS Returns, iid.remarks AS Remarks,Null AS Manual 
FROM inventory_issue_header AS iih, inventory_issue_detail AS iid,inventory 
AS t  WHERE  iid.inventory_id=t.id
    AND 
    iid.issue_header_id=iih.id

UNION ALL    
 SELECT t.item AS ITEM, iirh.return_date As  [Transaction Date], iir.item_id AS ID, Null AS Reciept, NULL AS Issued,iir.qyt AS Returns, iir.reasons AS Remarks,Null AS Manual 
FROM inventory_return_header AS iirh, inventory_return_detail AS iir, inventory AS t
WHERE      
iir.item_id=t.id
AND 
iir.return_header_id=iirh.id
 ) AS [ITEM Ledger]
WHERE ID=[Forms]![Reports Window]![cmb_ar]
and
[Transaction Date] between [Forms]![Reports Window]![ar_frm_dt] And [Forms]![Reports Window]![ar_to_dt];
4

1 回答 1

1

在标头中指定参数的数据类型

PARAMETERS 
    [Forms]![Reports Window]![cmb_ar] Long,
    [Forms]![Reports Window]![ar_frm_dt] DateTime,
    [Forms]![Reports Window]![ar_to_dt] DateTime;
SELECT 
    ITEM, [Transaction Date], ID, Reciept, Issued, Returns, Remarks, Manual
FROM
<snip>

附录

Sum可能会失败,因为由于第一个查询中的Null值,该字段作为文本返回。

一种解决方案是使查询期望字段值是数字。这可以通过以下表达式来实现:

IIf(False, 0, Null)

要检查的条件False永远不会是 True,因此表达式将始终返回 Null,但是 - 尽管如此 - 查询会评估两个输出选项并决定它是numeric

插入表达式,查询将显示:

SELECT 
    t.item AS ITEM, 
    irh.reciept_date AS [Transaction Date], 
    ird.inv_id AS ID, 
    ird.inv_qyt AS Reciept, 
    IIf(False, 0, Null) AS Issued, 
    IIf(False, 0, Null) AS Returns, 
    ird.remarks AS Remarks, 
    ird.inv_manual_number AS Manual
FROM 
    inventory_reciepts_header AS irh, 
    inventory_reciepts_detail AS ird, 
    inventory AS t
<snip>
于 2018-03-12T11:00:55.187 回答