How can I select all records that were entered / updated at the same time in multiple tables in SQL Server?
4 answers
If the DATETIME columns have the same name, you can generate queries like
select
'select * from '
+ t.name
+ ' where UpdateDate = ''2009-05-01''' as SelectStatement
from sys.tables as t
Or, if the DATETIME column name is not static, you can do something along these lines:
select
'select * from ' + t.name
+ ' where ' + c.name + ' = ''2009-05-01''' as SelectStatement
from sys.tables as t join sys.columns as c on t.object_id=c.object_id
where c.system_type_id = (select system_type_id from sys.types where name = 'datetime')
0
a source to share