WEB开发网
开发学院数据库MSSQL Server sqlserver 每30分自动生成一次 阅读

sqlserver 每30分自动生成一次

 2013-05-07 14:53:03 来源:开发学院   
核心提示: DECLARE @BeginTime AS DATETIMEDECLARE @EndTime AS DATETIMEDECLARE @Hour AS INTDECLARE @Min AS INTSET @Min = DATEPART(Minute, GETDATE())IF @Min < 30BEGINSET

 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

Tags:sqlserver 自动生成 一次

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接