DEV Community

Query Filter
Query Filter

Posted on

diag3

/* -------------------------------------------------------------
   ONE SINGLE BLOCK – paste & execute → 56 rows instantly
   Works on ALL old Sybase ASE versions (12.5 → 16.0)
   ------------------------------------------------------------- */

set nocount on
go

/* Use the maximum safe size */
declare @sql varchar(8000)
select @sql = ''

/* Build the UNION ALL string – NO line breaks inside the SQL */
select @sql = @sql + 
       'select ''' + o.name + ''' as table_name, count(*) from ' + 
       db_name() + '..' + o.name + 
       ' where INTERNTIMESTAMP >= dateadd(day,-10045,getdate()) union all '
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

/* Remove the trailing ' union all ' (exactly 11 chars) */
if len(@sql) > 11
   select @sql = left(@sql, len(@sql) - 11)
else
   select @sql = 'select ''No tables found'' as table_name, 0'

/* Optional – see what was generated (very useful) */
-- print @sql

/* Execute the full query */
exec (@sql)
go
Enter fullscreen mode Exit fullscreen mode

Top comments (0)