Inserting to SQL via Access

Hello Experts,
I have a seemingly simple problem:
I have an Access database table which is populated via integration with
small-parcel tracking information.  

The table has four columns: Order Type, Order Number, Tracking Number, and a Timestamp (Access gen).

What I need to do is write a Query that takes this table and inserts only the tracking numbers from the last 12 hours into a SQL Database table available to Access via ODBC.

The real issue I am having trouble with is the Timestamp filter.
DarkLookingGlassAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChetOS82Commented:
What is the datatype of the timestamp?  If it is Date/Time, then you could use something like:
SELECT * FROM Table1 WHERE Timestamp >= DateAdd('h', -12,  (Date() + Time()))

Open in new window

0
DarkLookingGlassAuthor Commented:
Chet,

Yes, the type is Date/Time.

What would the SQL Insert look like?
0
ChetOS82Commented:
I don't know the names of your tables or columns, but probably something like this:
INSERT INTO sqlTable (OrderType, OrderNumber, TrackingNumber, Timestamp) SELECT OrderType, OrderNumber, TrackingNumber, Timestamp FROM Table1 WHERE Timestamp >= DateAdd('h', -12,  (Date() + Time()))

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DarkLookingGlassAuthor Commented:
Chet,

I am getting "Number of Query Values and Destination Fields are not the same" error
INSERT INTO SOP10107 (SOPTYPE, SOPNUMBE, Tracking_Number) SELECT SOPTYPE, SOPNUMBE, Tracking_Number, Timestamp FROM tblTrackingNumbers WHERE Timestamp >= DateAdd('h', -12,  (Date() + Time()))

Open in new window

0
ChetOS82Commented:
Ok, remove the timestamp column from the SELECT statement.
0
DarkLookingGlassAuthor Commented:
should this be done in two queries?  One to SELCT from and another to INSERT to?
0
DarkLookingGlassAuthor Commented:
Chet,

oops...like this?

DLG
INSERT INTO SOP10107 ( SOPTYPE, SOPNUMBE, Tracking_Number )
SELECT SOPTYPE, SOPNUMBE, Tracking_Number
FROM tblTrackingNumbers
WHERE Timestamp>=DateAdd('h',-12,(Date()+Time()));

Open in new window

0
ChetOS82Commented:
No, it is one query.  You are asking for the timestamp in the SELECT query, but you arn't using it in the INSERT statement.

Just remove it from the list, like this:
INSERT INTO SOP10107 (SOPTYPE, SOPNUMBE, Tracking_Number) SELECT SOPTYPE, SOPNUMBE, Tracking_Number FROM tblTrackingNumbers WHERE Timestamp >= DateAdd('h', -12,  (Date() + Time()))

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DarkLookingGlassAuthor Commented:
Chet,

I think I have it.  Let me test it in situ now.

Thanks
DLG
0
ChetOS82Commented:
We had some cross-talk there.  Yes, your final query is correct.
0
DarkLookingGlassAuthor Commented:
Thank you, Chet!  
Tried it on a test recordset...shows up as needed.
And thanks for teaching me timestamp query syntax!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.