General information
Forum:
Microsoft SQL Server
Im definatly not a trigger guru, but in my experience, I suggest you use the update() function instead of the updated_columns() function. I have had nothing but problems with updated_columns().
if update(date) or update(jour_heure)
Its also alot eaiser to understand.
>I'm new with triggers in SQL Server....
>
>In table PUNCH, I have 3 columns: DATE (datetime), JOUR_HEURE (datetime) and DATE_PAYE (datetime). Obviously the table has more than 3 columns ;-)
>
>I want to have the value of DATE_PAYE derived from DATE and JOUR_HEURE when an INSERT or an UPDATE is fired agains that table.
>
>The rule is: IF JOUR_HEURE is before 5AM (the date portion is irrelevant), the DATE_PAYE should be DATE - 1 DAY, ELSE DATE_PAYE = DATE.
>
>I'm thingking of using a trigger (other ways ???) and I want the trigger to fire (on updates) only when IF DATE or JOUR_HEURE changes (USING COLUMNS_UPDATED, since DATE and )
>
>Here is my starting point:
>
>CREATE TRIGGER punch_maj_date_paye ON Punch
>FOR INSERT, UPDATE
>
>AS
> /* On vérifie si les colonnes 3 ou 4 on ete modifiees (Date et jour_heure) */
> IF (COLUMNS_UPDATED() & 12) > 0
> BEGIN
> IF JOUR_HEURE ....
>
> END
>GO
>
>
>Thanks
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only