2017-07-24 92 views
0

我無法使用下面的查詢過濾出零字段。在「3年平均」或「比較用法」字段中有許多記錄的零點仍然包含在結果中。訪問條件不等於零

Query

卸下「<> 0」或「不爲空」的標準沒有改變在輸出表中。訪問正在生成以下SQL:

SELECT 
[active plant parts made from dept produced components usage].assembly_item_no, 
[active plant parts made from dept produced components usage].component_item_no, 
[active plant parts made from dept produced components usage].component_qty, 
[active plant parts made from dept produced components usage].[3 yr average], 
[active plant parts made from dept produced components usage].[comp usage], 
noetix_sys_invus_category_all.[a$cat$item_type] 
INTO [department component usage and assembly type] 
FROM [active plant parts made from dept produced components usage] 
     INNER JOIN noetix_sys_invus_category_all 
       ON 
[active plant parts made from dept produced components usage].assembly_item_no = 
noetix_sys_invus_category_all.[a$item$item_number] 
WHERE ((( 
[active plant parts made from dept produced components usage].[3 yr average] 

) 
<> 0) 
    AND (( 
    [active plant parts made from dept produced components usage].[comp usage]) 
<> 0) 
    AND ((noetix_sys_invus_category_all. [a$cat$item_type]) = "aft")) 
OR ((( 
[active plant parts made from dept produced components usage].[3 yr average] 
) 
IS NOT NULL) 
    AND (( 
    [active plant parts made from dept produced components usage].[comp usage] 
     ) 
    IS NOT NULL) 
    AND ((noetix_sys_invus_category_all.[a$cat$item_type]) = "aft+")) 
OR (((noetix_sys_invus_category_all.[a$cat$item_type]) = "oem")) 
OR (((noetix_sys_invus_category_all.[a$cat$item_type]) = "oem+")) 
ORDER BY 
[active plant parts made from dept produced components usage].[3 yr average] DESC, 
[active plant parts made from dept produced components usage].[comp usage] DESC, 
noetix_sys_invus_category_all.[a$cat$item_type]; 

感謝您的幫助。

回答

2

也許簡化使用innz。我說也許是因爲我不完全確定你的預期結果。

WHERE nz([Active Plant Parts Made From Dept Produced Components Usage].[3 Yr Average],0)<>0 
    AND nz([Active Plant Parts Made From Dept Produced Components Usage].[Comp Usage],0)<>0 
    AND NOETIX_SYS_INVUS_CATEGORY_ALL.[A$CAT$ITEM_TYPE] in("AFT","AFT+","OEM","OEM+") 

或者聲明通常對於引擎評估來說是昂貴的;所以如果我們可以使用IN同時進行多個評估,我們就可以獲得性能優勢。

使用nz我們將零值轉換爲0,然後從結果中排除零。所以在3年平均或比較用量爲空或零的情況下,記錄被排除。

+1

IsNull在Access中不能像那樣工作,您需要使用Nz(Expression,0) – Minty

+0

我知道......在[Thursday](https://stackoverflow.com/questions/45222393/)上使用它sql-code-efficiency-compiling-issues-with-microsoft-access#comment77411148_45222393)...只是不玩w/access足以記住..謝謝你。我只是希望coalesce得到支持。這是我的defactor更改null爲大多數引擎。以及當不... – xQbert

+1

另請注意:由於這是一個create table語句,所以order by是不必要的;只是吃時間。從創建的表中選擇應該有按順序。插入的順序並不能真正幫助任何事情。 – xQbert

1

跨標準行讀取是AND語句,因此,例如Is Not Null僅適用於「AFT +」。

使用單行和And(或Or)關鍵字。實施例(在單個小區中鍵入):

<>0 And Is Not Null 

"X" Or "Y" Or "Z" 

或重複爲每個 「X」 的第一表達, 「Y」 等,行。