Say your date field in the table is "CreateDate" and the DateTime type is. Your time for comparison: GETDATE () (which returns the date + time) To get the datetime value 12 hours before, is done with DATEADD: DATEADD (hour, -12, GETDATE ())
therefore, if we want to add the number of rows in the last 12 hours, we will do the following:
SELECT COUNT(*) FROM Table WHERE CreateDate >= DATEADD(hour, -12, GETDATE())
in your proc, you must save the result of this request in a variable and check if it is> 0, therefore:
DECLARE @amount int SELECT @amount=COUNT(*) FROM Table WHERE CreateDate >= DATEADD(hour, -12, GETDATE())
and then you check the @amount variable if it is> 0.
source share