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.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • thanks for your input

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

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