| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| Hello all! I have a insert ,update trigger that fires when a specified column is updated (if update). This is working well. But when a new set of data is inserted into the table this trigger is doing nothing. I guess when a new set of data is inserted into the table my specified column is updated(if update) and therefor should fire!? Code is: CREATE TRIGGER INS_UPT_045004 ON [dbo].[ttdsls045004] FOR INSERT, UPDATE AS set nocount on declare @Stat as varchar(30) declare @nummer as int declare @position as int IF UPDATE (t_ssls) BEGIN SELECT @nummer = t_orno, @position = t_pono, @Stat = t_ssls from inserted IF @Stat = 1 SET @Status = 'great weather' ELSE IF @Stat = 8 SET @Status = 'not so great weather' ELSE IF @Status = 3 SET @Status = 'bad weather' ELSE IF @Status = 4 SET @Status = 'no weather at all' ELSE IF @Status = 6 SET @Status = 'midnight' ELSE IF @Status = 7 SET @Status = 'daylight' ELSE IF @Status = '' SET @Status = 'nothing' END Thanks in advance! |
|
#2
|
| Hi Your trigger does not handle multi inserts and/or updates. Try doing something like that SELECT @Stat = CASE WHEN t_ssls =1 THEN 'great weather' END ........ FROM inserted "krostpupe" news:FDCF9C2E-F4FB-4093-9857-554E7B103DB6-at-microsoft.com... > Hello all! > > I have a insert ,update trigger that fires when a specified column is > updated (if update). This is working well. But when a new set of data is > inserted into the table this trigger is doing nothing. I guess when a new > set > of data is inserted into the table my specified column is updated(if > update) > and therefor should fire!? > Code is: > > CREATE TRIGGER INS_UPT_045004 ON [dbo].[ttdsls045004] > FOR INSERT, UPDATE > AS > > set nocount on > > declare @Stat as varchar(30) > declare @nummer as int > declare @position as int > > > > IF UPDATE (t_ssls) > BEGIN > SELECT @nummer = t_orno, @position = t_pono, > @Stat = t_ssls from inserted > > IF @Stat = 1 SET @Status = 'great weather' > ELSE > IF @Stat = 8 SET @Status = 'not so great weather' > ELSE > IF @Status = 3 SET @Status = 'bad weather' > ELSE > IF @Status = 4 SET @Status = 'no weather at all' > ELSE > IF @Status = 6 SET @Status = 'midnight' > ELSE > IF @Status = 7 SET @Status = 'daylight' > ELSE > IF @Status = '' SET @Status = 'nothing' > END > > Thanks in advance! > |
![]() |
| Thread Tools | |
| Display Modes | |