declare @spid varchar(10)
declare @sql varchar(50)
Create Table #inputbuffer ([EventType] nvarchar(30),[Parameters] int,[EventInfo] nvarchar(4000),[SPID] varchar(10))
declare activesp cursor fast_forward for
select spid from master.dbo.sysprocesses where dbid > 1
open activesp
fetch next from activesp into @spid
while @@fetch_status = 0
begin
set @sql = 'dbcc inputbuffer(' + @spid + ')'
insert into #inputbuffer([EventType], [Parameters], [EventInfo])
exec (@sql)
update #inputbuffer set spid = @spid where spid is null
fetch next from activesp into @spid
end
close activesp
deallocate activesp
if @@cursor_rows <> 0
begin
close sprocket
deallocate sprocket
end
select * from #inputbuffer
drop table #inputbuffer
GO