declare @begintime datetime,@endtime datetime
set @begintime = getdate()
查询
set @endtime = getdate()
select datediff(millisecond,@begintime,@endtime) costtime
这样只能计算出毫秒的差别我想得到一个查询所用的时间,就像查询分析器下面的那样,但要精确到毫秒
set @begintime = getdate()
查询
set @endtime = getdate()
select datediff(millisecond,@begintime,@endtime) costtime
这样只能计算出毫秒的差别我想得到一个查询所用的时间,就像查询分析器下面的那样,但要精确到毫秒
set @begintime = getdate()
declare @I int
set @I = 1
while @i < 1000
set @i = @I + 1
set @endtime = getdate()
select @endtime - @begintime
set @begin=getdate()
Select s_Name from tb_Student
--这个就是你的时间
select [查询的时间(毫秒)]=datediff(ms,@begin,getdate())--或者用这个SET STATISTICS TIME ON
go select * from tablename SET STATISTICS TIME OFF
go
查询...set statistics time off这样?
set @begintime = getdate()
WAITFOR DELAY '00:00:3.45'
set @endtime = getdate()
DECLARE @I INT
SET @I = datediff(millisecond,@begintime,@endtime)
DECLARE @RESULT VARCHAR(20)
SET @RESULT = '.' + CAST((@I % 1000) AS VARCHAR)
SET @I = @I / 1000
IF @I > 0
BEGIN
SET @RESULT = ':' + CAST((@I % 60) AS VARCHAR) + @RESULT
SET @I = @I / 60
END
IF @I > 0
BEGIN
SET @RESULT = ':' + CAST((@I % 60) AS VARCHAR) + @RESULT
SET @I = @I / 60
END
SET @RESULT = CAST(@I AS VARCHAR) + @RESULT
SELECT @RESULT
set @begintime = getdate()
--WAITFOR DELAY '00:00:3.45'
set @endtime = dateadd(millisecond,20000847,getdate())
DECLARE @I INT
SET @I = datediff(millisecond,@begintime,@endtime)
DECLARE @RESULT VARCHAR(20)
SET @RESULT = '.' + CAST((@I % 1000) AS VARCHAR)
SET @I = @I / 1000
IF @I > 0
BEGIN
SET @RESULT = ':' + CAST((@I % 60) AS VARCHAR) + @RESULT
SET @I = @I / 60
END
IF @I > 0
BEGIN
SET @RESULT = ':' + CAST((@I % 60) AS VARCHAR) + @RESULT
SET @I = @I / 60
END
SET @RESULT = CAST(@I AS VARCHAR) + @RESULT
SELECT @RESULT
-- 结果
--------------------
5:33:20.846(1 行受影响)