给我看看这个SQL,我要加一条件加不了. ( 积分: 0 )

  • 主题发起人 主题发起人 leadroy
  • 开始时间 开始时间
L

leadroy

Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT dbo.V_StoreHouseComChange.ID,dbo.V_StoreHouseComChange.iGoodID, dbo.V_StoreHouseComChange.fThick,
dbo.V_StoreHouseComChange.fWidth, dbo.V_StoreHouseComChange.fPoint,
dbo.V_StoreHouseComChange.fInPrice, dbo.V_StoreHouseComChange.fAmount,
dbo.V_StoreHouseComChange.fAmount2, dbo.V_StoreHouseComChange. cLocalPackID,
dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice AS 应开发票,
已开发票=(Case when SUM(dbo.TaxMx.fAmount) <>0 then SUM(dbo.TaxMx.fAmount) else 0 end),
(dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice)-(Case when SUM(dbo.TaxMx.fAmount) <>0 then SUM(dbo.TaxMx.fAmount) else 0 end) as 未开发票,

dbo.V_StoreHouseComChange.iSelectTax,
dbo.V_StoreHouseComChange.fSelectTaxAmount
FROM dbo.TaxMx RIGHT OUTER JOIN
dbo.V_StoreHouseComChange ON
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.ID

WHERE (dbo.V_StoreHouseComChange.客户代号 = :lCusid) and (dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice>0) and (dbo.V_StoreHouseComChange.类型 =:lPtype)
GROUP BY dbo.V_StoreHouseComChange.ID,dbo.V_StoreHouseComChange.iGoodID,
dbo.V_StoreHouseComChange.iGoodType, dbo.V_StoreHouseComChange.fThick,
dbo.V_StoreHouseComChange.fWidth, dbo.V_StoreHouseComChange.fPoint,
dbo.V_StoreHouseComChange.fInPrice, dbo.V_StoreHouseComChange.fAmount2,dbo.V_StoreHouseComChange. cLocalPackID,
dbo.TaxMx.iStoreChangeID, dbo.V_StoreHouseComChange.fAmount,
dbo.V_StoreHouseComChange.iSelectTax,
dbo.V_StoreHouseComChange.fSelectTaxAmount


我要将"未开发票"的值=0的值全部去除,不用dataset的FILTER功能,要在SQL 语句中实现.
 
为什么不好加阿,在WHERE 后加上不就行了
 
帮你顶,好长呀
 
已解了.解决方式为:
SELECT dbo.V_StoreHouseComChange.ID,dbo.V_StoreHouseComChange.iGoodID, dbo.V_StoreHouseComChange.fThick,
dbo.V_StoreHouseComChange.fWidth, dbo.V_StoreHouseComChange.fPoint,
dbo.V_StoreHouseComChange.fInPrice, dbo.V_StoreHouseComChange.fAmount,
dbo.V_StoreHouseComChange.fAmount2, dbo.V_StoreHouseComChange. cLocalPackID,
dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice AS 应开发票,

已开发票=(case when (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id)<>0 then (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id) else 0 end) ,

(dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice)-(case when (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id)<>0 then (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id) else 0 end) as 未开发票,

dbo.V_StoreHouseComChange.iSelectTax,
dbo.V_StoreHouseComChange.fSelectTaxAmount
FROM dbo.TaxMx RIGHT OUTER JOIN
dbo.V_StoreHouseComChange ON
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.ID

WHERE (dbo.V_StoreHouseComChange.客户代号 = :lCusid) and (dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice>0) and (dbo.V_StoreHouseComChange.类型 =:lPtype)
GROUP BY dbo.V_StoreHouseComChange.ID,dbo.V_StoreHouseComChange.iGoodID,
dbo.V_StoreHouseComChange.iGoodType, dbo.V_StoreHouseComChange.fThick,
dbo.V_StoreHouseComChange.fWidth, dbo.V_StoreHouseComChange.fPoint,
dbo.V_StoreHouseComChange.fInPrice, dbo.V_StoreHouseComChange.fAmount2,dbo.V_StoreHouseComChange. cLocalPackID,
dbo.TaxMx.iStoreChangeID, dbo.V_StoreHouseComChange.fAmount,
dbo.V_StoreHouseComChange.iSelectTax,
dbo.V_StoreHouseComChange.fSelectTaxAmount

HAVING ((dbo.V_StoreHouseComChange.fAmount * dbo.V_StoreHouseComChange.fInPrice)-(case when (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id)<>0 then (SELECT SUM(dbo.TaxMx.fAmount)
FROM dbo.taxmx
WHERE dbo.taxmx.bBad = 0 AND
dbo.TaxMx.iStoreChangeID = dbo.V_StoreHouseComChange.id) else 0 end) >0)
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
635
import
I
I
回复
0
查看
735
import
I
I
回复
0
查看
680
import
I
后退
顶部