About Me

Barking, Essex, United Kingdom
MCITP DBA ,MCITP BI & Oracle OCP 11G

Monday, May 16, 2016

Get the data within the current hour if query executed at any duration


use DBA

IF OBJECT_ID('tempdb..#checkwaptreport') IS NOT NULL
    DROP TABLE #checkwaptreport
             
Declare @currentdate date
set @currentdate=getdate()
declare @currenthour int
--declare @columnc bigint=17

Declare @enddate datetime
set @enddate=getdate()

--print @enddate

SET @currenthour= DATEPART(hh,getdate())

declare @startdate datetime

SELECT @startdate=CONVERT(DATETIME, CONVERT(CHAR(8), @currentdate, 112)
    + ' ' + LEFT(RIGHT('0' + @currenthour, 4),2)
    + ':' + RIGHT(00, 2))

--print @startdate


No comments:

Post a Comment