making ledger report from two tables


making ledger report from two tables



I have two tables ledgertable,openingtable I want a report like given below using both the tables like this:
Item No. | Item Name | opening | Date | Voucher No. | Purchase | Issue | Return | Department | balance | Remarks



1 Ac Box 2 01/12/2018 20180000000044 1 3.00
09/16/2017 2017916005 1 III DORM 2.00 for Commen Room, Collected by Kishan
10/07/2017 2017107003 1 III DORM 1.00 Collected by Sanjay
09/15/2017 2017000000461 1 2.00
10/06/2017 2017000000526 1 3.00
I am not getting the query how to do it. I have written a query but it is giving wrong result in balance column. Basically all the values are coming right but I am getting problem to calculate balance.
Here is my query :
"select l.trandate,l.voucherno,l.itemno,l.itemname,l.recieve,l.issue,l.returnback,l.to_dept,o.opening,l.remarks,balance = ((o.opening+isnull(recieve,0)+isnull(returnback,0))-isnull([issue],0))+isnull((select sum((isnull(recieve,0)+isnull(returnback,0))-isnull([issue],0)) from ledgertable b where b.voucherno < l.voucherno and b.itemno=l.itemno),0) from ledgertable l join openingstock o on l.itemno=o.itemno where l.trandate between '" + startdate + "' and '" + enddate + "'"
I am attaching image of result which I am getting with this queryenter image description here









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

PHP contact form sending but not receiving emails