February 15, 2007 at 2:37 pm
I know how to get the results of a DBCC command or stored proc into a table. But my real goal is to get it into a variable.
Of course, I could read it into a table and then select from the table into a variable. But can I do it all in one step somehow, that is put the results of a DBCC command into a variable with something like
select @inputbuffer = exec ('dbcc inputbuffer(20)') ?
I assume this will never work because there are essentially three columns output from this? Anyway, if you know how to make it work, I'd love to know. Otherwise, I'll read it into a table and then select off that table.
February 15, 2007 at 2:44 pm
What type of variable are you trying to get it into? I would assume a table variable and if so, you just declare your table variable and then insert into it just like a table.
February 15, 2007 at 3:40 pm
I don't think you can insert into a table variable using exec. You will need to insert into a table and select into your variables.
February 15, 2007 at 4:31 pm
declare
@MyTable TABLE
(
[wait type]
varchar(150),
Requests
float,
[Wait Time]
float,
[Signal Wait Time]
float
)
insert
into @MyTable
exec
('dbcc sqlperf(''waitstats'')')
select
* from @MyTable
this works fine in sql 2005. You cannot do a select into with a table variable though
February 15, 2007 at 4:39 pm
Ah, you are correct. It works fine in SQL Server 2005. I was working in SQL Server 2000 where this will not work. Sorry for the confusion.
February 15, 2007 at 5:06 pm
Thx guys. I had a bone-headed syntax error.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply