Home Forums SQL Server 2008 T-SQL (SS2K8) Insert a Total Row Into a Dynamic Table For Reporting RE: Insert a Total Row Into a Dynamic Table For Reporting

  • Get the column names from sys.columns -- if it is a table it will have a row in sys.objects and one row for each column in sys.columns. Here's a query that I use:

    select Case when ROW_NUMBER() over (order by column_id) > 1 then ',' else '' end+C.name

    from sys.sysobjects O

    join sys.columns C on O.id = C.[object_id]

    where O.type = 'U' and O.name = '##zzz'

    order by column_id

    The probability of survival is inversely proportional to the angle of arrival.