Joe Green
Joe Green

Reputation: 207

Populate data with current date only

I have table A that populated every day with data.

And I have another table B that keep historical data from table A. How can I populate data from table A to table B with current date data only?

thanks, S

Please advice, thanks

Upvotes: 0

Views: 56

Answers (2)

John Cappelletti
John Cappelletti

Reputation: 81990

Assuming TableA and TableB have the same structures:

Insert Into TableB
 Select * From TableA where YourDateField > (Select MaxDate=max(YourDateField) From TableA)

Here we are checking for the max date in TableB so that data does NOT get duplicated

Upvotes: 1

Sparrow
Sparrow

Reputation: 2583

You can create a SQL server agent job and schedule it to run once a day. The job can run a stored procedure, which populates or copies the data for you.

See these links for more details:

https://www.mssqltips.com/sqlservertip/3052/simple-way-to-create-a-sql-server-job-using-tsql/

https://msdn.microsoft.com/en-us/library/ms187910.aspx

Upvotes: 0

Related Questions