Gaurav arora 0 Junior Poster in Training

hi all, i m working on a project(Inventry System) in which i have to update stock frequently. i have created a trigger in SQl for stock updation. if i insert for a particular product in stock table the previous quantity and the current inserted quantity must be added. Plus i have a column name mTotal_amount that calculates the total stock in money for that product. i need that also be updated with quantity. following is the structure of the tables
Product Table............
cProduct_code vProduct_name vProduct_desc iPrice
Stock Table..............
cProduct_code vProduct_name vProduct_desc iQty mTotal_Amount
And the code i written for trigger is as follows

Alter Trigger StockUp
on StockRec
for Insert
As
Declare @Prod_id char
Declare @Price int
Declare	@Qty int
Declare	@Total_amount money
Declare @qoh int
select @prod_id = cProd_id from inserted
select @Price = iPrice from Product
select @Qty = iQty from StockRec 
select @qoh = iqty from inserted 
select @total_amount = mTotal_amount from StockRec 
if(@Qty > 0)
begin
update Stockrec set iqty = @qty + @qoh where cprod_id = @prod_id
update Stockrec set mtotal_amount = @Qty * @Price where product.cProd_id = stockrec.cprod_id
end

But my code is not producing the result i needed. can anyone tell me where is the problem. Thnks a lot

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.