Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update timestamp with Trigger.

Posted on 2006-07-20
1
Medium Priority
?
829 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 200 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

722 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