Solved

Update timestamp with Trigger.

Posted on 2006-07-20
1
824 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now