2016-05-12 60 views
0

我有這個查詢奇怪的問題。當我按原樣運行時,我得到了一個結果集,但是當我以任何方式更改WHERE子句或甚至刪除它時,它完全消除了我的整個結果集。任何想法,爲什麼這可能是?這是一箇舊的,糟糕的供應商平臺,不幸的是,我無法擁有管理員訪問權限,所以我所能做的就是運行報告,而且只能運行報告。SQL Server - 刪除WHERE子句刪除結果集

SELECT 
    (CASE WHEN SUBSTRING(VO.AR090_REFERENCE, 1, 1) = 'X' THEN 'CLUB' WHEN LEFT(RIGHT(VO.AR090_REFERENCE, 5), 2) = 'IP' THEN 'IP' ELSE 'CAMP' END) AS TYPE, 
    CONVERT(NVARCHAR, VO.AR090_ISS_DATE, 101) AS SETUP, 
    VO.AR090_DESC AS FUNDER, 
    VO.AR090_REFERENCE AS VOUCH_NUM, 
    CHECKSUM(VO.AR090_REFERENCE) AS VOUCH_PARM, 
    CONVERT(NVARCHAR, VO.AR090_UPD_STAMP, 101) AS MODIFIED, 
    VO.AR090_AMT AS AMT, 
    VO.AR090_AMT_APPLIED AS USED, 
    VO.AR090_AMT - VO.AR090_AMT_APPLIED AS REMAIN 

FROM AR090_VOUCHER VO 
    LEFT OUTER JOIN AR020_TRANSACTIONS AR2 ON VO.AR090_ORG_CODE = AR2.AR020_ORG_CODE AND VO.AR090_REFERENCE = AR2.AR020_CC_CHECK AND AR2.AR020_TRANS_TYPE = 'VCH' 
    LEFT OUTER JOIN ER100_ACCT_ORDER AO ON AO.ER100_ORG_CODE = AR2.AR020_ORG_CODE AND AO.ER100_ORD_NBR = AR2.AR020_ORD_NBR 

WHERE 
    (VO.AR090_AMT - VO.AR090_AMT_APPLIED) > 0 

GROUP BY 
    VO.AR090_ISS_DATE, 
    VO.AR090_REFERENCE, 
    VO.AR090_AMT, 
    VO.AR090_AMT_APPLIED, 
    CONVERT(NVARCHAR, VO.AR090_UPD_STAMP, 101), 
    AR2.AR020_TRANS_TYPE, 
    AR2.AR020_CC_CHECK , 
    VO.AR090_DESC 

ORDER BY 
    (CASE WHEN SUBSTRING(VO.AR090_REFERENCE, 1, 1) = 'X' THEN 'CLUB' WHEN LEFT(RIGHT(VO.AR090_REFERENCE, 5), 2) = 'IP' THEN 'IP' ELSE 'CAMP' END) DESC, 
    SUBSTRING(VO.AR090_DESC, 13, LEN(VO.AR090_DESC) - 12) 
+1

爲什麼GROUP BY? (我看不到任何聚合函數。) – jarlh

+0

因爲他確實想殺死重複項;) – TomTom

+0

我想知道是否有一些空值可能無意中忽略了where子句。 –

回答

0

不,我沒有看到任何情況(正確地)刪除where子句會導致LESS數據。要麼這是一個錯誤(並且這將是一個非常罕見的錯誤或完全沒有維護的系統),或者顯然不只是刪除他在where子句(通過邏輯推理)。