how to optimize this query

  • INSERT INTO SELECT * FROM data (NOLOCK) WHERE DATEDIFF(hh,()) > 64

    Thanks for your help

  • You should get a performance improvement if you take the dynamic getdate() out of the queries ...

    declare @now datetime

    set @now = getdate()

    INSERT INTO monitordata

    SELECT * FROM data (NOLOCK) WHERE DATEDIFF(hh,time_stamp,@now) > 6

    DELETE data WHERE DATEDIFF(hh,time_stamp, @now) > 6

    This will also ensure that exactly the same resultsets are returned for both the INSERT and the DELETE queries.


  • thanks for your input

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

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