欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

sqlserver 每30分自动生成一次

程序员文章站 2022-04-24 10:58:03
...

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,

  DECLARE @BeginTime AS DATETIME

  DECLARE @EndTime AS DATETIME

  DECLARE @Hour AS INT

  DECLARE @Min AS INT

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

  IF @Min

  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