Event within last 2 minutes

  • I have a table with a colum called lastupdated.

    I need to find any records that where updated in the last 2 minutes based on getdate()

    the lastupdated column data type is datetime

     

    any help would be appreciated.

     

    thanks

     

  • CREATE TABLE #TableA (ID int, LastUpdated datetime)

    INSERT INTO #TableA VALUES(1, DATEADD(d,-1,getdate()))

    INSERT INTO #TableA VALUES(2, DATEADD(mi,-1,getdate()))

    SELECT * FROM #TableA WHERE LastUpdated > DATEADD(mi,-2,getdate())

    DROP TABLE #TableA

  • SELECT ...

    FROM MyTable

    WHERE LastUpdated between dateadd(n, -2, GETDATE()) and GETDATE()

     

    _____________
    Code for TallyGenerator

  • Thank you, this is what I was trying to don on my own but couldn't.

     

    GF

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply