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 |
|
invisible777
Starting Member
10 Posts |
Posted - 2007-04-30 : 16:07:06
|
| I have a trigger that is supposed to compare inserted data against another table (basically it's supposed to automatically grade an exam or quiz). Below is the trigger I have setup to make this comparison, but when I run it, it inserts a brand new row of data with all Null's except for the 'rightwrong' column. So basically I have two rows, one with the inserted data, one with the trigger data that I just need to combine.I think it has to do with that last line (the insert line) but I'm not sure how to specify which precise row to update...Thanks |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-04-30 : 17:20:49
|
I would probably do this as a update to all records, and not as a triger on the insert.I think this is what you were looking forUpdate aset a.rightWrong = case i.TestID when null then 0 else 1 endfrom TestAnswers aLeft Join Inserted ion I.TestID = a.TestIDand i.questionNbr = a.QuestionNbrand a.answer = i.answer |
 |
|
|
invisible777
Starting Member
10 Posts |
Posted - 2007-04-30 : 17:44:07
|
| Hi Vinnie... everything is being marked with a '1' (correct answer) with that update... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 00:16:44
|
quote: I have a trigger that is supposed to compare inserted data against another tableCreate Trigger insertTestAnswerson TestAnswers for insert
You want record to be inserted back to TestAnswers ?From what i understand it should be an UPDATE trigger. When you insert records into the TestAnswers table, the update trigger will update the column rightWrong. Is it ? KH |
 |
|
|
|
|
|