Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating current record via a trigger 1

Status
Not open for further replies.

Kelin

Technical User
Dec 12, 2002
11
US
I am trying to update the current record a user is working on via a trigger but it is updating all of the records since I cannot designate the actual record in the trigger.

CREATE TRIGGER TimeDate ON dbo.Asgnmnt
FOR INSERT, UPDATE, DELETE
AS
Update Asgnmnt
set TimeAssign = (select convert(varchar(8),getdate(),108) as [time])
*where callid = 'whatever the callid is the client is working on'*

*This is where I would need it to update the particular record the user is working on, in this case a callid.*
 
Two virtual tables are accessable within a trigger: Inserted and Deleted. Updates are a combination of the two statements. These virtual tables only exist during the transaction and have the same structure as the table being modified. Join to these tables to "touch" the rows being modified. In your case, I suspect the trigger would look something like this:

Code:
CREATE TRIGGER TimeDate ON dbo.Asgnmnt
FOR INSERT, UPDATE, DELETE 
AS
BEGIN
Update Asgnmnt
set TimeAssign = (select convert(varchar(8),getdate(),108) as [time])
FROM Asgnmnt a JOIN Inserted i ON a.CallID = i.CallID

Update Asgnmnt
set TimeAssign = (select convert(varchar(8),getdate(),108) as [time])
FROM Asgnmnt a JOIN Deleted d ON a.CallID = d.CallID
END
--Angel
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
That worked perfectly. Thank you very much for the assistance.

Kelin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top