Ok.....I have 3 forms...the first form has a table with Number,Item_Code,Item_Description and opening_balance as its attributes.
The second table has purchase_number,Item_Code,Item_Description,purchase_date and quantity purchased as its attributes and the 3rd table has issue_number,item_code,number_of_issues,issue_date,issue_to_whom,name_of_person, returnable_or_non-returnable ,balance and remarks as its attributes...
the item codes in the 2nd nd 3rd table may be repeated but in the first table the item_codes must be unique...
my job is to calculate the opening_balance in the first table and balance in 3rd table...both are same.
balance is calculated as opening_balance(from 1st table) + quantity_purchased(from 2nd table) - no_of_issue(from 3rd table).

plz help me find a solution for my above problem...
my above mentioned tables along with all necessary database connectivity is done and working.
i just need the solution for calculating my balance...
plz help.
Thank You in advance. :)

Recommended Answers

All 5 Replies

>i just need the solution for calculating my balance...

Simply, execute select statement.

Select opening_balance from table1 where itemcode='1001' 

select sum(quantity_purchased) from table2 where itemcode='1001'

select sum(no_of_issue) from table3 where itemcode='1001'

The problem with the above solution is that while the 2nd and 3rd tables have repetitive item_code attributes its not the same with the 1st table...
hence this code will actually give me 3 rows filled with a data from each of the 3tables instead of a single row with combined value.
Thank You for your feedback...but sadly, this code does not help me.

but sadly, this code does not help me

In fact, I didn't post any code. I have no idea about database product you are using. Please post your code here. Wrap programming code within posts in code tags.

Ok, firstly, why is this a poll? It needn't be and thats probably why you have received down votes.
Secondly, your question stated that "balance is calculated as opening_balance(from 1st table) + quantity_purchased(from 2nd table) - no_of_issue(from 3rd table)."
Adatapost has given you the queries you need to retrieve each of the values for your calculation.
Its really not a very big step from there to your total.
retrieve each value into variables:
openingBalance = (retrieve results of query:Select opening_balance from table1 where itemcode='1001')
quantityPurchased = (retrieve results of query: select sum(quantity_purchased) from table2 where itemcode='1001')
issueNo = (retrieve results of query: select sum(no_of_issue) from table3 where itemcode='1001')

balance = openingBalance + quantityPurchased - issueNo;

You said you have already coded for the data access so i have left you to implement the running of the queries.

Solved it finally guys. :-)
Thank You for the support. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.