Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Long running Insert stored proc

$
0
0
Hi all,I was wondering if someone could help me figure out why this Insert statement is taking 9 minutes to run. It never took that long before and now, all of the sudden, it is taking longer and longer to complete.Here is the statementINSERT INTO Metrics (Application, App1_Performance, App1_Availability, App2_Performance, App2_Availability, week, Current_Week)SELECT COALESCE (n.Application, k.Application) AS Application, AVG(n.Performance) AS App1_Performance, AVG(n.Availability) AS App1_Availability, AVG(k.Performance) AS App2_Performance, AVG(k.Availability) AS App2_Availability, COALESCE (DATEPART(wk, n.Timestamp), DATEPART(wk, k.Timestamp)) AS INPUT_WEEK, DATEPART(wk, GETDATE()) AS CURRENT_WEEKFROM Table2 kFULL OUTER JOIN Table1 nON k.Application = n.ApplicationLEFT JOIN Metrics fON f.Application = COALESCE (n.Application, k.Application)WHERE NOT EXISTS (SELECT week FROM Metrics WHERE week != DATEPART(wk, n.Timestamp) OR week != DATEPART(wk, k.Timestamp))GROUP BY COALESCE (n.Application, k.Application), COALESCE (DATEPART(wk, n.Timestamp), DATEPART(wk, k.Timestamp))Table1 and Table2 have about 12,000 rows.I delete everything from Metrics each time the stored procedure is run.Is it just the computations with that many records that is taking too long? Is there anyway to make it faster?

Viewing all articles
Browse latest Browse all 3145

Trending Articles