Solved

Update timestamp with Trigger.

Posted on 2006-07-20
1
826 Views
Last Modified: 2008-01-09
I'm a MSSQL novice and I am trying to create a trigger that will copy data as it is inserted into the results table of one DB into a tblBReagleresult table in another DB. I have succeeded in copying the data, but I also want to insert the date and time that the record was updated also. Now I have the syntax listed below but it will modify the time on all records in that field. We are currently using MSSQL 7.0, here is the trigger I have.

CREATE TRIGGER [CopyResults] ON [dbo].[result]
FOR INSERT
AS
INSERT INTO [STOCKYARDS].[dbo].[tblBReagleresult]([ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID])
SELECT [ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID] FROM INSERTED
update [STOCKYARDS].[dbo].[tblBReagleresult]
set [transtime]=getdate()
0
Comment
Question by:power4350
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 50 total points
ID: 17151443
CREATE TRIGGER [CopyResults] ON [dbo].[result]
FOR INSERT
AS
INSERT INTO [STOCKYARDS].[dbo].[tblBReagleresult]([ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID], [transtime])
SELECT [ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID], GETDATE() FROM INSERTED
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question