create11

Published: (December 3, 2025 at 04:44 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

SQL Script

declare @sql varchar(8000)
select @sql = ''
select @sql = @sql + 'select "'+name+'" , count(*) from '+name+
              ' where INTERNTIMESTAMP >= dateadd(dd,-45,getdate()) union all '
from sysobjects where type='U' 
  and exists (select 1 from syscolumns c where c.id=object_id(name) and c.name='INTERNTIMESTAMP')
order by name

-- remove the trailing ' union all '
select @sql = substring(@sql,1,len(@sql)-11)  
exec(@sql)
Back to Blog

Related posts

Read more »

create12

T-SQL script for DBVisualizer to count rows added in last 45 days

compare5

SQL Script sql -- Declare variables for schema UIDs run once DECLARE @uid1 int, @uid2 int SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1' SEL...

compare4

sql -- First get the user IDs once optional, for readability DECLARE @uid1 int, @uid2 int SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1' SELE...