2013-05-09 7 views
6

Ho bisogno di ottenere il tempo di esecuzione della mia richiesta. Sto usandoCome ottenere il tempo di esecuzione della query corretto in SQL Server?

declare @starttime datetime 
declare @endtime datetime 
set @starttime =getdate() 

-- execute my query here 

set @endtime = GETDATE() 
select @[email protected] 

Ma l'uscita è venuta come 1900-01-01 00:02:10.707

mi serve solo la parte del tempo.

+0

Partenza http://stackoverflow.com/questions/595762/calculate-execution-time-of-a-sql-query – Rohan

risposta

2

Utilizzare il tipo di dati time che è disponibile in SQL Server 2008 e versioni successive

Ora i tag sono corretti e questo è SQL Server 2005 ...

select CONVERT(varchar(12), @[email protected], 114) 
+0

Sto usando SQLServer 2005 –

+1

@ user2360877: e allora perché questo tag SQL Server 2008? – gbn

+0

E 'stato modificato –

0
 
DECLARE @StartTime datetime,@EndTime datetime 
SELECT @StartTime=GETDATE() 

--La tua query per essere eseguito va qui--

 
SELECT @EndTime=GETDATE() 
SELECT DATEDIFF(ms,@StartTime,@EndTime) AS [Duration in microseconds] 
5

Utilizzare questa:

set statistics time on 
--query 
set statistics time off 

poi passare alla scheda 'Messaggio' per vedere un messaggio come questo:

SQL Server Execution Times: 
    CPU time = 0 ms, elapsed time = 165 ms. 
2

SET TEMPO STATISTICHE {ON | OFF}

esempio

USE AdventureWorks2012; GO

SET STATISTICS TIME ON;

GO

SELEZIONA ProductID, StartDate, EndDate, StandardCost DA Production.ProductCostHistory DOVE StandardCost < 500,00;

GO

SET STATISTICS TIME OFF;

GO

Problemi correlati