Monday, September 30, 2013

SQL Trigger


ALTER TRIGGER [dbo].[TR_Buy_ChangeTransferStatus]
   ON [dbo].[Buy]
   AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare
@StockID decimal(18,0),
@Item_id nvarchar(10),
@Transfer nvarchar(1)

Select @StockID=StockID,@Item_id=Item_id,@Transfer=Coalesce(Transfer,'N') From deleted

IF(@Transfer='Y')
BEGIN
    UPDATE Buy SET Transfer='N' WHERE StockID=@StockID AND Item_id=@Item_id
END




No comments:

Post a Comment