Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get last changes - timestamp

Author  Topic 

4colors
Starting Member

2 Posts

Posted - 2009-04-07 : 15:24:25
Is there any way to show all modified or added records in a table based on a field that has timestamp as a datatype?

for example

select ID, Name, DOB, mytimestamp
from employee
where mytimestamp (Changed/added)


in the previous example i would like to show all employee information wherever timestamp field changes or modified

Many thanx


-----------------------
Smile

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-07 : 15:27:38
Modified or changed since when?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

4colors
Starting Member

2 Posts

Posted - 2009-04-07 : 23:18:59
quote:
Originally posted by Peso

Modified or changed since when?



I want to keep getting all records that changed at anytime (i mean whenever mytimestamp changes)

*i depended on timestamp becoz i couldn't think of another idea. if you have better idea please let me know

& many many Thanx

-----------------------
Smile
Go to Top of Page

asgast
Posting Yak Master

149 Posts

Posted - 2009-04-08 : 04:13:31
i think you want two different things combined in one
you can have an after update trigger to time stamp data change, then if you select mytimestamp is not null you'll get data that was modified in the table.

example
create TRIGGER yourtriger ON yourtable
AFTER UPDATE
AS

SET NOCOUNT ON

UPDATE dbo.yourtable SET mytimestamp =GETDATE()
FROM yourtable y
INNER JOIN inserted i ON i.ID=y.ID

this will change mytimestamp everytime a row is updated
Go to Top of Page
   

- Advertisement -