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)
 Logic to Copy data from one table to another

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2009-10-08 : 10:34:52
Dear All,
I need to maintain the History of records in one table from another table.
Here there can be multiple records for the same Date.But i need to insert the latest one records to History table.

Can u pls tell me how can we do this ?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-08 : 10:48:53
Until you give more informations

insert into history_table(columns)
select columns from original_table
where date=(select max(date) from original_table)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2009-10-08 : 11:26:22
Here is the details.The main table holds the data for 5 days after the it get purged.So i need to store these table details in History table.It has the same structure as the main table.Also it should be stored procedure to run as Schedule job after completion of getting values to main table.
Pls help
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-09 : 01:50:19
Did you try what I suggested?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -