SQL: Sample Cursors
declare @sqlhandle as varbinary(64)
DECLARE sqlhandle CURSOR FOR
select most_recent_sql_handle from sys.dm_exec_connections ec1
open sqlhandle
fetch next from sqlhandle into @sqlhandle
while @@FETCH_STATUS = 0
begin
begin try
insert into #temp(sqltext)
select text from sys.dm_exec_sql_text(@sqlhandle)
end try
begin catch
print @sqlhandle
end catch
fetch next from sqlhandle into @sqlhandle
end
close sqlhandle
deallocate sqlhandle
No comments:
Post a Comment