用了多少時間
declare @BTIME datetime
declare @ETIME datetime
select @BTIME = getdate()
select @ETIME = dateadd(second,2,getdate())
select datediff (second,@BTIME,@ETIME),@BTIME,@ETIME --FOR SQL SERVER/SYBASE
select SECONDS(@BTIME,@ETIME),@BTIME,@ETIME --FOR SYBASE
DROP TABLE #WORK_LOG
CREATE TABLE #WORK_LOG (ID VARCHAR(30),SDATE DATETIME,EDATE DATETIME ,COSTSECOND INT )
DROP TABLE #SS,#EE
SELECT 'JOB A' ID ,GETDATE() DATE INTO #SS
SELECT 'JOB A' ID ,dateadd(second,2,getdate()) DATE INTO #EE
INSERT INTO #WORK_LOG (ID,SDATE,EDATE,COSTSECOND)
SELECT T1.*,T2.DATE,datediff (second,T1.DATE,T2.DATE) AS COSTTIME FROM #SS T1 INNER JOIN #EE T2 ON T1.ID = T2.ID
SELECT * FROM #WORK_LOG
DECLARE @SDATE DATETIME
DECLARE @EDATE DATETIME
SET @SDATE = GETDATE()
SET @EDATE = GETDATE()
PRINT CONVERT(VARCHAR(30),@SDATE ,121) +'到'+CONVERT(VARCHAR(30),@EDATE ,121) +';所花時間:'+CAST(DATEDIFF(SECOND, @SDATE,@EDATE) AS VARCHAR(30))