Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
EugeneLim11
Posting Yak Master
167 Posts |
Posted - 2008-12-17 : 23:37:11
|
| Hi Experts, I need a bit of help on Triggers.I got a table named Attendance, with a column named Day (this is a numberic value), and another column name Status (this is a char) and will be either 0 or L. The unique identifier is studentID (another column). Now when I insert the values 0 or L into the 'Status' column for a new record, I want to a trigger to fire and add in value 0.25 the 'Day' column if the value of status column is 'L' and (0.5) in the 'Day' column if the value of status column is '0'Create Trigger Tri_InsertDayCount on AttendanceTable AFTER INSERT AS BEGIN Insert into AttendanceTable ([day]) values ('0.25') where xx Insert into AttendanceTable ([day]) Values ('0.50') where xxEND GO The problem I am facing is that I am not sure how to retrieve the inserted value of Status column, as indicated by xx.Help is very much appreciated. Thank youRegards,Eugenecheck out my blog at http://www.aquariumlore.blogspot.com |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 23:44:34
|
| [code]Create Trigger Tri_InsertDayCount on AttendanceTable AFTER INSERT AS BEGINUPDATE tSET t.Day=CASE WHEN t.Status ='0' THEN 0.5 ELSE 0.25 ENDFROM AttendanceTable tINNER JOIN INSERTED iON i.studentID=t.studentIDEND GO [/code] |
 |
|
|
EugeneLim11
Posting Yak Master
167 Posts |
Posted - 2008-12-18 : 01:27:41
|
| Visakh16,Thank you. this resolve the problem perfectly. :) The table I need to get data from is Inserted table.Regards,Eugenecheck out my blog at http://www.aquariumlore.blogspot.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-18 : 01:39:29
|
welcome |
 |
|
|
|
|
|