日期:2014-05-18  浏览次数:20510 次

关于下面SQL语句肯能产生的错误,求指点
SQL code
SELECT  DISTINCT  RE_RepairBills.cHouseCode,RE_RepairBills.dCheckTime,RE_RepairBills.cReBillCode, RE_InDepotLog.cGoodsCode, RE_RepairBills.cHouseCode, MT_Goods.cGoodsPN, MT_Goods.cGoodsCName, 
CASE RE_RepairBills.cBillType WHEN '200611070002' THEN 'DOA新品' WHEN '200611070001' THEN '新品' ELSE '新品' END AS shuxing, 
SUM(RE_InDepotLog.rAmont) AS 'rAmont', MT_Goods.cGoodsPN AS 'cGoodsPN1', MT_Goods.cGoodsCName AS 'cGoodsCName2', 
RE_InDepotLog.cGoodsCode AS 'cGoodsCode2'
FROM         RE_RepairBills LEFT OUTER JOIN
                      RE_InDepotLog ON RE_RepairBills.cReBillCode = RE_InDepotLog.cReBillCode LEFT OUTER JOIN
                      MT_Goods ON MT_Goods.cGoodsCode = RE_InDepotLog.cGoodsCode
WHERE     (RE_RepairBills.cBillState = '检测') 
            AND (RE_InDepotLog.cReGoodsClassCode = '200611180001') 
            and (RE_RepairBills.isread is NULL or RE_RepairBills.isread='0')
            and (RE_RepairBills.cHouseCode='200604100018')
            and (RE_RepairBills.dCheckTime>'2010-7-21' AND RE_RepairBills.dCheckTime<'2010-7-22')


用户页面就两个下拉列表,不存在用户自己输入的地方,都是选的,用户可以进行筛选的就是RE_RepairBills.dCheckTime 和 RE_RepairBills.cHouseCode 也就是日期和库房号。 
现在的问题就是输入进去之后,有的数据能查到有的却查不到,大家帮着想想问题可能出现在哪里可能有问题
应该就是where里面。。虽然这有些断章取义。。不过还是抱着点希望发上来让大家帮帮忙。

------解决方案--------------------
在查询分析器里执行看看
------解决方案--------------------
SQL code



 and (RE_RepairBills.cHouseCode='200604100018')

------解决方案--------------------
SQL code

SELECT  DISTINCT  RE_RepairBills.cHouseCode,RE_RepairBills.dCheckTime,RE_RepairBills.cReBillCode, RE_InDepotLog.cGoodsCode, RE_RepairBills.cHouseCode, MT_Goods.cGoodsPN, MT_Goods.cGoodsCName, 
CASE RE_RepairBills.cBillType WHEN '200611070002' THEN 'DOA新品' WHEN '200611070001' THEN '新品' ELSE '新品' END AS shuxing, 
SUM(RE_InDepotLog.rAmont) AS 'rAmont', MT_Goods.cGoodsPN AS 'cGoodsPN1', MT_Goods.cGoodsCName AS 'cGoodsCName2', 
RE_InDepotLog.cGoodsCode AS 'cGoodsCode2'
FROM         RE_RepairBills LEFT OUTER JOIN
                      RE_InDepotLog ON RE_RepairBills.cReBillCode = RE_InDepotLog.cReBillCode LEFT OUTER JOIN
                      MT_Goods ON MT_Goods.cGoodsCode = RE_InDepotLog.cGoodsCode
WHERE     (RE_RepairBills.cBillState = '检测') 
            AND (RE_InDepotLog.cReGoodsClassCode = '200611180001') 
            and (RE_RepairBills.isread is NULL or RE_RepairBills.isread='0')
            and (RE_RepairBills.cHouseCode='200604100018')
            and (RE_RepairBills.dCheckTime>'2010-7-21' AND RE_RepairBills.dCheckTime<'2010-7-22')