在SUM中用自定義函數理論上是應該不會錯的。你先試著看結果是否真的如你所說的那樣?select left(spbh,7) as spbh,dbo.fn_dwhs(spbh,isnull(byxssl,0)) as xssl,
dbo.fn_dwhs(spbh,isnull(qcsl,0)) as qcsl,
from t_yzmjzkc
where left(jzsj,4)='2002'
and right(jzsj,2)='04'
and bmbh='04' and left(spbh,7) ='4110205' AND CKBH IS NULL--結果是多少?
dbo.fn_dwhs(spbh,isnull(qcsl,0)) as qcsl,
from t_yzmjzkc
where left(jzsj,4)='2002'
and right(jzsj,2)='04'
and bmbh='04' and left(spbh,7) ='4110205' AND CKBH IS NULL--結果是多少?
spbh qcsl xssl
------- ------------------------ ------------------------
4110205 32.902016 4.6922116
查询出结果如下--
spbh qcsl xssl
------- ------------------------ ------------------------
4110205 32.902016 4.6922116(所影响的行数为 1 行)
请各位多多教!
http://www.csdn.net/expert/topic/674/674934.xml?temp=.5688593