Skip to content
Advertisement

Find all tables with a specific column name + where value is lower than X

I need help in searching our database. So we have this problem that we need to know all tables, with the column_name “sysmodified” and see if there are any entries before a specific date (25-sep-2019).

I tried to find the answer on google and stackoverflow, but I either get an answer how to get the results before 25-sep within 1 table Example1, or results how to get all tables, which has this column_name Example2.

Using the code I have so far (see below), we know that there are 325 tables, which contain the column_name “sysmodified”. I could manually use example 1 to get my information, but I was hoping for a way to get the results that I need with just one query.

This is what I have so far:

However if I try to enter anything like sysmodified < ‘20190925’. I get errors

or this approach, which also results in errors

based on (but I cannot add 325 columnnames in FROM?)

Hopefully someone could help me with an approach how to tackle this problem. We use Microsoft SQL Server Management Studio 17 (if that might be relevant).

Advertisement

Answer

This is fairly simple dynamic sql to put together. This should produce the results you are looking for as I understand your requirements.

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