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 2012 Forums
 Transact-SQL (2012)
 Create a timestamp when a new record is created

Author  Topic 

djamit
Starting Member

17 Posts

Posted - 2014-02-20 : 10:50:14
Hello SQL team,

I have a table and everyday records are imported in this table.
In this table names of patients with instant numbers are imported.
I have situations where one patient name have more then one instant number. So I only need to know wich instant number is the last one imported. I was thinking of adding a timestamp when each record imported so that I can know wich was the last one.
How can I solve this issue?
Another option is to delete the old records and only hold the last one of each patient name.

Thanks,

Best Regards

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-02-20 : 12:54:31
You can add column of DATETIME type with a default value of getdate() - which would tell you the time the record was imported.
ALTER TABLE YourTable ADD ImportTimestamp DATETIME DEFAULT(GETDATE()) NOT NULL;
Alternatively, if you don't care about the time, but just want the latest record, you can add an identity column and look for the highest number for any given patient.
ALTER TABLE YourTable ADD Id INT NOT NULL IDENTITY(1,1);
In either case, make sure that your import process can correctly handle the presence of an additional column. The import process would not need to fill in the column - it just shouldn't break because there happens to be another column.
Go to Top of Page

djamit
Starting Member

17 Posts

Posted - 2014-02-21 : 06:05:55
Thanks James K
I used the first case and it works ok
Go to Top of Page
   

- Advertisement -