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:
Expand|Select|Wrap|Line Numbers
- --------------------------------------------------------
- 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.