Insert, Update Trigger with If update

This is a discussion on Insert, Update Trigger with If update within the sqlserver-server forums in Microsoft SQL Server category; 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, @...

Go Back   Database Forum > Microsoft SQL Server > sqlserver-server

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-28-2008, 04:21 AM
Default Insert, Update Trigger with If update

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!

Reply With Quote
  #2  
Old 08-28-2008, 06:40 AM
Default Re: Insert, Update Trigger with If update

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" wrote in message
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!
>



Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 07:13 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.