SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Create a timestamp when a new record is created
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djamit
Starting Member

16 Posts

Posted - 02/20/2014 :  10:50:14  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3587 Posts

Posted - 02/20/2014 :  12:54:31  Show Profile  Reply with Quote
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

16 Posts

Posted - 02/21/2014 :  06:05:55  Show Profile  Reply with Quote
Thanks James K
I used the first case and it works ok
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000