Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
djokerss
Starting Member
28 Posts |
Posted - 2005-11-28 : 04:08:47
|
| i have 2 query , the fist like these :******************************************set dateformat dmydeclare hitungpiutang cursor scroll forselect a.ckdtrans,a.ntotal,coalesce((select sum(ntotal) from tbretur where ckdtrans=a.ckdtrans and lposting=1 and lbatal=2),0) as xretur,coalesce((select sum(b.nbayar) from tbdetpiu bleft join tbpiu c on b.cnoref=c.cnorefwhere c.lposting=1 and b.lbatal=2 and c.lbatal=2and b.ckdtrans=a.ckdtrans),0) as xbayarfrom tbtrans awhere a.ckdtrans='xxx' declare @gcckdtrans char(20),@gctotal numeric,@gcretur numeric,@gcbayar numericopen hitungpiutangfetch next from hitungpiutang into @gcckdtrans,@gctotal,@gcretur,@gcbayarwhile @@fetch_status=0beginselect @gcckdtrans,@gctotal,@gcretur,@gcbayarfetch next from hitungpiutang into @gcckdtrans,@gctotal,@gcretur,@gcbayarendclose hitungpiutangdeallocate hitungpiutangthat query give me result xxx , 10000,0,153960and the second is from the first query without declare ********************select a.ckdtrans,a.ntotal,coalesce((select sum(ntotal) from tbretur where ckdtrans=a.ckdtrans and lposting=1 and lbatal=2),0) as xretur,coalesce((select sum(nbayar) from tbdetpiu bleft join tbpiu c on b.cnoref=c.cnorefwhere c.lposting=1 and b.lbatal=2 and c.lbatal=2and b.ckdtrans=a.ckdtrans),0) as xbayarfrom tbtrans awhere a.ckdtrans='xxx'***********************the second query give me the same data, except the fourth column ,it return 24 , and this is the correct one.why the first query for fourth column give me 153960 and the second 24 ? whats wrong with my query |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-28 : 04:16:15
|
| Is Null the reason?Instead ofselect sum(nbayar) from tbdetpiu buseselect sum(IsNull(nbayar,0)) from tbdetpiu bMadhivananFailing to plan is Planning to fail |
 |
|
|
djokerss
Starting Member
28 Posts |
Posted - 2005-11-28 : 20:46:16
|
| i've tried , but it doesnt change... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-29 : 02:28:58
|
| Are you still getting error?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|