use mytest drop proc [dbo].[begin_schedstats] go CREATE proc [dbo].[begin_schedstats] as set nocount on if exists (select 1 from sys.objects where object_id = object_id ( N'[dbo].[my_schedstats]') and OBJECTPROPERTY(object_id, N'IsUserTable') = 1) drop table [dbo].[my_schedstats] create table [dbo].[my_schedstats] ( [scheduler_id] int not null, [preemptive_switches_count] bigint not null, [context_switches_count] bigint not null, [idle_switches_count] bigint not null, [current_tasks_count] bigint not null, [runnable_tasks_count] bigint not null, [current_workers_count] bigint not null, [active_workers_count] bigint not null, [work_queue_count] bigint not null, [load_factor] bigint not null, [yield_count] bigint not null, now datetime not null default getdate()) declare @i int, @myspid smallint, @now datetime begin select @now = getdate() --select @myspid = @@SPID insert into [dbo].[my_schedstats] ( [scheduler_id], [preemptive_switches_count] , [context_switches_count] , [idle_switches_count] , [current_tasks_count] , [runnable_tasks_count] , [current_workers_count] , [active_workers_count] , [work_queue_count] , [load_factor] , [yield_count] , now) select [scheduler_id], [preemptive_switches_count] , [context_switches_count] , [idle_switches_count] , [current_tasks_count] , [runnable_tasks_count] , [current_workers_count] , [active_workers_count] , [work_queue_count] , [load_factor] , [yield_count] , @now from sys.dm_os_schedulers end