萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mssql數據庫 >> sqlserver 每30分自動生成一次

sqlserver 每30分自動生成一次

   DECLARE @BeginTime AS DATETIME

  DECLARE @EndTime AS DATETIME

  DECLARE @Hour AS INT

  DECLARE @Min AS INT

  SET @Min = DATEPART(Minute, GETDATE())

  IF @Min < 30

  BEGIN

  SET @BeginTime = CONVERT(VARCHAR(10), GETDATE(), 120) + ' ' + CAST(DATEPART(Hour, GETDATE()) AS VARCHAR) + ':30'

  SET @EndTime = CONVERT(VARCHAR(10), GETDATE(), 120) + ' ' + CAST(DATEPART(Hour, GETDATE()) AS VARCHAR) + ':00'

  SET @BeginTime = DATEADD(Hour, -1, @BeginTime)

  END

  ELSE

  BEGIN

  SET @BeginTime = CONVERT(VARCHAR(10), GETDATE(), 120) + ' ' + CAST(DATEPART(Hour, GETDATE()) AS VARCHAR) + ':00'

  SET @EndTime = CONVERT(VARCHAR(10), GETDATE(), 120) + ' ' + CAST(DATEPART(Hour, GETDATE()) AS VARCHAR) + ':30'

  END

  EXEC up_GenReport @BeginTime, @EndTime

copyright © 萬盛學電腦網 all rights reserved