Hi all,
I am beginner on SQL and I am stuck with trigger.
I'm trying to create a Trigger for two columns (KG ,Items)
Basicly if column KG is inserted/updated then compute column Items. If column Items is inserted/updated then compute column KG.
It is kind of converter.I have tried as below:
Is no problem when colums is updated (procedure from excel spreadsheet), updated is only one column KG or Items, but when is new record then updated column has a null value and another computed column is calculate absolutely correctly.
Thanks for any advice.
I am beginner on SQL and I am stuck with trigger.
I'm trying to create a Trigger for two columns (KG ,Items)
Basicly if column KG is inserted/updated then compute column Items. If column Items is inserted/updated then compute column KG.
It is kind of converter.I have tried as below:
Code:
-------------------------------------------------------- CREATE TRIGGER [dbo].[UpdateItemsOrKg] ON [dbo].[UpdateItemsOrKg] AFTER INSERT,UPDATE AS BEGIN SET NOCOUNT ON; DECLARE @Factor decimal(8,3) SELECT @Factor=Factor FROM dbo.CurrentFactors IF UPDATE(Items) BEGIN UPDATE [dbo].[UpdateItemsOrKg] SET [KG] = @items*@Factors END IF UPDATE(KG) BEGIN UPDATE [dbo].[UpdateItemsOrKg] SET [Items] = @KG/@Factors END --------------------------------------
Thanks for any advice.
Comment