DEV Community

Query Filter
Query Filter

Posted on

cursor7

set nocount on
go

-- Step 1: Just get the table names first
select 'Table to check: ' + o.name
from sysobjects o
where o.type = 'U'
  and exists (select 1 from syscolumns c 
              where c.id = o.id and c.name = 'INTERNTIMESTAMP')
order by o.name
go

-- Step 2: Then check a few at a time manually
select 
    'select ''' + o.name + ''' as table_name, ' +
    'count(*) as rows_last_45_days ' +
    'from ' + o.name + ' ' +
    'where INTERNTIMESTAMP >= dateadd(day, -45, getdate()) ' +
    'union all ' as query_fragment
from sysobjects o
where o.type = 'U'
  and exists (select 1 from syscolumns c 
              where c.id = o.id and c.name = 'INTERNTIMESTAMP')
  and o.name in ('Table1', 'Table2', 'Table3')  -- Check a few at a time
order by o.name
go
Enter fullscreen mode Exit fullscreen mode

Top comments (0)