| Author |
Topic  |
|
|
brandonl
Yak Posting Veteran
58 Posts |
Posted - 12/20/2004 : 00:08:28
|
I have a table RECORDS, that has a StateID in it and a RecordID (primary key). StateID is an integer that links to a STATE table.
What I want to do is make a trigger that, anytime a record in the RECORDS table gets updated, the trigger checks if the new StateID = 8. If it is, it inserts a new record into a PILOT_TESTING table (which has a foreign key RecordID that links back to the RECORDS table). It also checks that if, in the PILOT table, that RecordID already exists, it clears out the values in that record.
I can do the select statements to find out the new stateid after the update, and can do the insert statement, and the update statements. What I need help with, is how do I accomplish what I need to do in the trigger. Do I do it with an if then, case, etc? Sorta like this?
select updated record (stateid, and recordid) from updates if new stateid = 8 then select from PILOT table where recordid = if of the updated record if record exists update record in PILOT else insert new record end if end if
Am I on the right track with this?
~BrandonL |
|
|
Bustaz Kool
Flowing Fount of Yak Knowledge
USA
1430 Posts |
Posted - 12/20/2004 : 01:33:50
|
create trigger u_Records on dbo.Records for update as begin if update(StateID) insert into dbo.Pilot_Testing ( RecordID, StateID ) select RecordID, StateID from inserted where StateID = 8
delete from dbo.Pilot where RecordID in (select RecordID from Inserted) end
I'm not sure what you meant by "clear the values" from the Pilot table so I implemented it as a DELETE statement.
HTH
=================================================================
Happy Holidays! |
 |
|
|
brandonl
Yak Posting Veteran
58 Posts |
Posted - 12/20/2004 : 09:48:32
|
quote: Originally posted by Bustaz Kool
I'm not sure what you meant by "clear the values" from the Pilot table so I implemented it as a DELETE statement.
I'll give your code a try, and see if that's a start.
By clear the values-in the PILOT table, there's a recordid and some bit fields. Basically, when someone checks off on a web form, it sets the bit value to 1, otherwise it's blank. If there's already a record in the PILOT table for that requestid, I want it to set the bit values to NULLs.
~BrandonL |
 |
|
| |
Topic  |
|
|
|