Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default value trigger
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Default value trigger
Miscellaneous
Thread ID:
00810601
Message ID:
00810601
Views:
60
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
Next
Reply
Map
View

Click here to load this message in the networking platform