Skip to content
Advertisement

Most recent datetime column and count for each table

I have a DB that has 1000+ tables. 100 of those tables are prefixed with a three letters (let’s say ‘ABC’) Only half of those prefixed tables have MODIFIEDDATETIME column.

I’m trying to do a simple select query to get all the last updated MODIFIEDDATETIME stamp for each Table that actually has a MODIFIEDDATETIME on that table and also begins with the three letter prefix.

I’ve tried using this function but it doesn’t seem to be getting me there. Thoughts?

Advertisement

Answer

You could do it with dynamic SQL, but this will probably not be very efficient on 1000 tables!

It basically builds a query like

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement