INSERT INTO monitordata SELECT * FROM data (NOLOCK) WHERE DATEDIFF(hh,time_stamp,@now) > 6 DELETE data WHERE DATEDIFF(hh,time_stamp, @now) > 6 Thanks in advance
Get rid of the * and replace it with the column names. Place the date logic so you're not causing a table scan and can use the indexes. SELECT col1, col2 FROM data WITH(NOLOCK) WHERE time_stamp > DATEADD(HH,@now,6) This should give you an idea. MeanOldDBA derrickleggett@hotmail.com When life gives you a lemon, fire the DBA.