SQL Server - 删除WHERE子句删除结果集

时间:2016-05-12 13:43:59

标签: sql sql-server database reporting

我对此查询有一个奇怪的问题。当我按原样运行时,我得到一个结果集,但是当我以任何方式更改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 个答案:

答案 0 :(得分:0)

没有。我认为没有(正确)删除where子句会导致LESS数据的情况。这是一个错误(这将是一个非常罕见的错误或完全没有维护的系统,或者你显然不只是删除他的where子句(通过逻辑演绎)。