Get sum to root

Sir, I have these codes
[php]while($res = sqlsrv_fetch_array($result)) {
echo “”;
$sno=$sno+1;
echo “$sno”;
echo “”.($res[‘acc_code’])."";
$partycode=($res[‘acc_code’]);
$query1 = “select code,desc1 from master where code=’”.$partycode."’";
$result1 = sqlsrv_query($con,$query1) or die (“Error”. sqlsrv_errors($con)) ;
while($res1 = sqlsrv_fetch_array($result1)) {
echo “”.($res1[‘desc1’])."";
}
echo “”.($res[‘dr_amount’] != 0 ? number_format(abs($res[‘dr_amount’])):’’)."";
echo “”.($res[‘cr_amount’] != 0 ? number_format(abs($res[‘cr_amount’])):’’)."";

}[/php]

The query generates this result

Attachment #1

But I want this result

Attachment #2

Please help


Looks like you are missing some of the code that is generating the page. I need more information

Thanks

Sir here are complete codes

[php]Select codes,;
sum(Iif(data1.dr_amount + data1.cr_amount)>0, (Sum(data1.dr_amount) + Sum(data1.cr_amount)),0) As dr_amount,;
Sum(Iif(data1.dr_amount + data1.cr_amount)<0, (Sum(data1.cr_amount) + Sum(data1.dr_amount)),0) As cr_amount;
FROM(;
SELECT codes,open_dr As dr_amount,open_cr As cr_amount;
From Master;
union All;
SELECT codes,dr_amount,cr_amount;
From purchase;
union All;
SELECT codes,dr_amount,cr_amount;
From sales);
as data1;
where Len(codes)=7 Group By Left(codes,4)"

[/php]

Why are you looping thru the results twice?

You SQL statement is a mess. Not sure why the line ending is a semi-colon, hopefully, that was just for my benefit?

Thanks for helping

Sir I refer to this link for complete detail

Inwhich sir #diafol tried his best to solve out my problem but unfortunately it is still unsolvable.

I think you can solve, you know better.

Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service