Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any feedback on my first SQL Server trigger
Message
From
16/02/2006 15:25:38
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01096860
Message ID:
01096867
Views:
13
Only thing I'd add is

REPLACE repmod with DATE() IN Dept

>I'm converting an app from VFP to SQL Server 2005 and I've just had a stab at converting my first trigger. Any comments on the code I used. The purpose of the trigger is to update a field with the current date, if 1 of 2 fields have changed.
>
>VFP Function called by the record validation event.
>
>
>FUNCTION dept_rv()
>	
>	SELECT dept
>	IF 	dept.repdate <> oldval("repdate","dept") OR ;
>		dept.repstaff <> oldval("repstaff","dept")
>		REPLACE dept.repmod WITH date()
>	ENDIF
>
>	RETURN .T.
>ENDFUNC
>
>SQL Server Update Trigger
>
>
>set ANSI_NULLS ON
>set QUOTED_IDENTIFIER ON
>go
>
>ALTER TRIGGER [Trigger_Dept_Update] on [dbo].[dept] AFTER UPDATE AS
>    IF UPDATE(repdate) or UPDATE(repstaff)
>		BEGIN
>			UPDATE Dept SET repmod = GETDATE() FROM Dept INNER JOIN inserted ON dept.id = inserted.id
>		END
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform