How can I select all records that were entered / updated at the same time in multiple tables in SQL Server?

is there someone who can help me select multiple records that were entered / updated in different tables at the same time in a SQL Server database. Do you think this is possible or not?

Your help is greatly appreciated, thanks!

0


a source to share


4 answers


Does your table have a date / time column of type DATETIME?

Otherwise, you are probably out of luck ....



Mark

+1


a source


Hm ... maybe it's as simple as

SELECT   * 
FROM     MyTable 
WHERE    CreatedDate = 'the date you are interested in'

      

or



SELECT   * 
FROM     MyTable 
GROUP BY CreatedDate
HAVING   COUNT(*) > 1

      

?

0


a source


if you are inside an insert trigger, you can query the pseudo table inserted

.

0


a source


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







All Articles