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
 General SQL Server Forums
 New to SQL Server Programming
 Last updated history table SQL search

Author  Topic 

avitron2020
Starting Member

3 Posts

Posted - 2015-02-25 : 20:24:13
I’m working on an existing database that has a table like the following:

Table Name: account_info
id
first_name
last_name
account_number
amount

Example data:
1, John, Smith, 1-271342, 600.00
2, Marty, Kent, 1-236342, 100.00
3, Bill, Jones, 1-174234, 350.00
etc.


I have another table that tracks when the ‘account_info‘ table above has been last updated:

Table Name: account_update_history
id
last_updated
agent_who_updated
account_info_id

Example data:
1, 2015-02-04 04:23:43, Jill Beth, 2
2, 2015-02-03 12:27:14, Jill Beth, 2
3, 2015-02-01 14:31:32, Jill Beth, 2
4, 2015-02-03 23:43:52, Bob Smith, 1
5, 2015-02-01 06:23:42, Bob Smith, 1
etc.

The ‘account_update_history’ table can have many entries depending upon how many times the ‘account_info’ table has been updated. Where each of these rows points back to an 'account_info' row from the first table

My question is, I want to pull data from the database daily but only if an ‘account_info’ row has been recently updated (like for instance, the last 24 hours). What’s the best way to do this efficiently? I have thousands of records to scan daily.

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2015-02-26 : 01:06:58
last_updated>=dateadd(hh,-24,getdate())
Go to Top of Page
   

- Advertisement -