SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query to analyze Concurrent Use


Query to analyze Concurrent Use

Author
Message
Cole.Mietzner
Cole.Mietzner
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 57
First off, I dont even know where to start with this. I do not expect anyone to do my work for me, but a push in the right direction would be great.

I have a table that lists every task run through our application. It logs a StartTimeDate and an EndTimeDate. I would like to see what tasks are running concurrently to help better our performance. I would like the results in 5min increments and limited to a week at a time. I honestly have no clue how to even start to write a statement to perform this as I am a QA engineer with moderate SQL skills.

I have created a sample DB at: http://sqlfiddle.com/#!3/beb7a/1

Any help would be greatly appreciated. Or if there is a program out there that does this already that would be awesome too.
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15021 Visits: 14396
First approach that came to mind:

1. Setup a tally table in your environment.

SET NOCOUNT ON ;
GO

-- Credit: http://www.sqlservercentral.com/articles/T-SQL/62867/
--DROP TABLE dbo.tally

--=============================================================================
-- Create and populate a tally table
--=============================================================================
IF NOT EXISTS ( SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'dbo.tally')
AND type IN (N'U') )
BEGIN
--===== Create and populate the tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY( INT,1,1 ) AS n
INTO dbo.tally
FROM master.dbo.SysColumns sc1,
master.dbo.SysColumns sc2

--===== Add a Primary Key to maximize performance
ALTER TABLE dbo.tally
ADD CONSTRAINT PK_Tally_N
PRIMARY KEY CLUSTERED (n) WITH FILLFACTOR = 100

--===== Let the public use it
GRANT SELECT, REFERENCES ON dbo.tally TO PUBLIC

PRINT 'Created tally table.'
END
GO



2. Use the tally table to create a time-table with a start and end time that spans 5 minute increments:

SELECT  DATEADD(minute, n - 5, CAST(CAST(GETDATE() AS DATE) AS DATETIME)) AS StartTime,
DATEADD(millisecond, n * 60000 - 3, CAST(CAST(GETDATE() AS DATE) AS DATETIME)) AS EndTime
FROM DBA.dbo.tally
WHERE n > 0
AND n % 5 = 0
AND n <= 1440;



3. Use the time-table created in step 2 to join to the Watson table to group events into 5 minute buckets.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search