hello everyone..I would be grateful if anybody could help me in performing subtraction from diffrent tables...
My Database has a Asset table which has opening balance and balance left coloums in it.and i have one store table which has received/issued item and its quantity.Wat i want to do is if i select receive in a combo box and enter the quantity it should be deducted /added from the opening balance and remaining should be displayed in balance quantity.Plzzz help me its Urgent

Recommended Answers

All 5 Replies

hmmm, where is the question? I don't know in what you have problem.

the quantity is not deducting from the quantity wat should i do to deduct the quantity??

Update statement:
You should send the ID and the Value be deduction from the existing quantity

Update Table 
Set Quantity = Quantity - @Value 
Where ID=@ID

Update statement:
You should send the ID and the Value be deduction from the existing quantity

Update Table 
Set Quantity = Quantity - @Value 
Where ID=@ID

i hv used this query bt its showing syntax error...can u help me with this
String query = "update Asset SET Unit= " +(asset.Unit-store.Quantity) + " where ItemCode = '" + asset.ItemCode;

This is the wrong forum, please post future SQL questions to the MSSQL forum (or respective rdbms).

Try a query like this:

Update Asset
Set Unit = Asset.Unit -
(
  Select Sum(Store.Quantity)
  From Store
  Where Store.ItemCode = Asset.ItemCode
)

The above query will work for a 1-to-1 or a 1-to-many relationship since you did not provide information on how the tables are joined.

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.