Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi everyone ,,
my main question is i want ti know how many items left in store like {table1.column - table2.column}
and if my question is not clear i will try say what i want accomplish
i have created view that consist of many table and if i set laptop_quantity=25
the first customers took 5 i want quantity automatically be equaled - assign
ID |Customers: items  | location  |quantity_store| assign|
1  [ johns   ][ Lapto  ] [  ITdep][    20        ] [  5   ]  
2  [ james   ][ Lapto  ] [  ITdep ][   16        ] [  4   ]               
3  [cilena   ][computer] [Accessdep][  16        ] [  0   ]

so is this can be done by trigger or what?

any answer will be so appreciated
and sorry if my question is not clear
Posted
Updated 4-May-15 20:57pm
v3
Comments
KaushalJB 5-May-15 5:39am    
Update your question with the query that you have tried till now.

From the above you need to have a column that has the item that you want to aggregate with. In your example you have [Customers: items] which has the customer name and the item name together. You need to separate the item name from the customer first.

Secondly, to have a total count of the quantity and assigned you can then run a group by query, e.g.

SQL
select item, sum(quantity_store) as qty, sum(assign) as out from stock group by item;


this will give you a qty of 36 and out of 10 per item in stock

Unfortunately your question is still very unclear however at column level, you can run a query like this

SQL
select item, sum(quantity_store) as qty, sum(assign) as out, (quantity_store - assign) as instock from stock group by item;


this returns the difference between quantity_store and assign. Hope it helps somehow.
 
Share this answer
 
in first thanks a lot to you guys especially Anele...i knew that my question was not clear enough but what to do that all i could do,,, but after a lot of search i found question it have same issue and the question is if you have table
CSS
Inventory CurrentQuantity OpenedOrder
  SKU1        300             50
  SKU2        100             10

Quote:
Each order will be processed individually. How can I have the database automatically update the inventory tablet after each order is processed?
i.e
If the order has 2 SKU1 in it got processed, the the inventory table will automatically show 298

and the suggest answer is
SQL
CREATE PROC dbo.ProcessOrder
    @Item int,
    @Quantity int
AS
BEGIN
    --Update order table here
    INSERT INTO dbo.Orders(ItemID,Quantity)
    VALUES (@ItemID, @Quantity)

    --Update Inventory here
    UPDATE dbo.Inventory
    SET CurrentQuantity = CurrentQuantity - Quantity
    WHERE ItemID = @ItemID
END

but i still cannot understand how does this works i? i know trigger can insert value to table but store producer how ?
any tutorial or idea will be so appreciated thanks again
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900