How do I dump the results of @exec sp_spaceused @tableName to a user table.I have a lookup table which has the servername, databasename and tablename. Now the sp_spaceused should execute in a cursor for each server (link servers), database and table in the lookup table and save the output to a user table.I think I would need cursors and dynamic sql. The lookup table is somewhat like this:ServerName Database TableName BR_AT_Ships DB1 tbl1BR_AT_Ships DB1 tbl2BR_AT_Ships DB1 tbl3BR_SIN_Ships DB1 tbl1BR_SIN_Ships DB1 tbl2BR_SIN_Ships DB1 tbl3
The final output table 'TableSize' should look like this:CREATE TABLE [dbo].[TableSize]( [ServerName] [nvarchar](300) NULL, [DatabaseName] [nvarchar](100) NULL, [Table] [nvarchar](200) NULL, [rowcnt] [int] NULL, [reserveddata] [varchar](100) NULL, [data] [varchar](100) NULL, [index_size] [varchar](100) NULL, [unused] [varchar](100) NULL, [ReportDate] [datetime] NULL, [ReportTime] [datetime] NULL) ON [PRIMARY]
Can someone please help me in how to write this query?Thanks,