Click here to Skip to main content
15,888,195 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i made an stored proc
SQL
ALTER proc [dbo].[MakeOrder]
@barcode varchar(50),
@packs int ,
@units int,
@Eid int 
as
begin

insert into Orders (Barcode,Price,PacksQty,UnitQty)
values (@barcode,dbo.GetOrderPackPrice(@packs,@barcode)+dbo.GetOrderUniPrice(@units,@barcode),@packs,@units)

insert into OrderDetails(Eid,Date)
values (@Eid,GETDATE())

update Product
set Stock = Stock-@packs , UnitsStock = UnitsStock-@units where BarCode=@barcode

end


and i want to make after update trigger to check the value of UnitsStock Column After Update If it 0 do something else do another thing
Posted

Follow link below

Triggers -- Sql Server[^]
 
Share this answer
 
Try this

CREATE TABLE Product(Id INT, Stock INT,UnitsStock INT)
INSERT Product VALUES(1,100,200),(2,200,400),(3,300,600),(4,400,800)
GO

CREATE TRIGGER trUnitStocks ON Product
FOR UPDATE
AS
BEGIN
    DECLARE @UnitStocks INT
    SET @UnitStocks = (SELECT I.UnitsStock FROM INSERTED I)
    
    IF @UnitStocks = 0
       PRINT 'When unitstocks 0'
       --Your code--
    ELSE
       PRINT 'When unitstocks is not 0'
       --Your code--   
END
GO
UPDATE Product SET UnitsStock = 100 WHERE Id = 2

Result:-

When unitstocks is not 0
(1 row(s) affected)
 
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