Groups | Blog | Home
all groups > sql server (microsoft) > february 2006 >

sql server (microsoft) : newbie sql server job step command to copy dated records to another table


frowg
2/22/2006 2:55:36 PM
We have an application where we are trying to copy old appointments to
a history table on a nightly basis at 2:00 am.

In SQL 2000 Enterprise Mgr, Managment, Jobs we've created a job with
just one step.
The step is of type TSQL and the command is as follows:

INSERT INTO TempAppt
SELECT * FROM MasterAppt

This works well for copying all the records, however, when i add a
WHERE to the command I get no records at all.

INSERT INTO TempAppt
SELECT * FROM MasterAppt
WHERE MasterAppt.ApptDateTime < DATE

ApptDateTime is set as datatype datetime

When i tried the same sql line in an Access query, it worked fine.
Hence the confusion.

TIA
Jens
2/22/2006 11:09:14 PM
Guess you are using the wrong function to evaluate the current data (if
you want to use the current date):

INSERT INTO TempAppt
SELECT * FROM MasterAppt
WHERE MasterAppt.ApptDateTime < GETDATE()

HTH; jens Suessmeyer.
Madhivanan
2/24/2006 5:53:54 AM
I think this is what you want

INSERT INTO TempAppt
SELECT * FROM MasterAppt
WHERE MasterAppt.ApptDateTime <
DateAdd(day,Datediff(day,0,GETDATE()),0)

Madhivanan
AddThis Social Bookmark Button