0

I am getting error while inserting data inside table TableSizes with below query, Could anyone please help me in this regard.

declare @name varchar(256)
select @name ='TestTable'
begin
insert into workdb..TableSizes
exec sp_spaceused @name
end
go
Msg 156, Level 15, State 2
Server '<ServerName>', Line 5
Incorrect syntax near the keyword 'exec'.

Thanks in advance.

Voonic
  • 4,667
  • 3
  • 27
  • 58
Manoj
  • 1
  • First, try running without any variables..`insert into workdb..TableSizes exec sp_spaceused TestTable` Since that does not work, I would question whether you can pass the output of a system stored procedure that way. – Mike Gardner Sep 30 '13 at 12:40

1 Answers1

0

So what you are trying to do here is to insert a proc result set into a table, which is not allowed unless the table is a proxy table. If not, then complete the insert statement.

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130