Auto export of previous days data from MS SQL table

  • Thread starter Thread starter elainejhnsn
  • Start date Start date
E

elainejhnsn

Hello, each day I need to get the previous days data from MS SQL table
into a .csv file automatically. Has anyone done this before in a
script, or can point me in the right direction of how to start this?

I have been working on the query below to get the previous days data
to display:

select *
from [table name]
where [EntryDate] = GETDATE()
AND [EntryDate] = DATEADD(DAY, -1, GETDATE())

Can some one let me know what is incorrect in this where statement, it
does not select the previous days data.

Thank you for your help in advance!
 
I don't think Entry Date will ever have avalue that is equal to today's date
and simultaneously equal to yesterday's date which is what your posted SQL
says.

WHERE are you running this query?
How are you linked to the MS SQL table - are you using an ODBC connection?

More details, please. The following might work for you if you are running
the query on the server or as a passthrough query.

SELECT *
FROM [TableName]
WHERE [EntryDate] <= GETDATE()
AND [EntryDate] >= DATEADD(DAY, -1, GETDATE())

Otherwise you might need to use the following if you are doing this from
Access

SELECT *
FROM [TableName]
WHERE [EntryDate] <= Date()
AND [EntryDate] >= DATEADD("d", -1, Date())


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top