Question

We are pulling data from several informix servers on a monthly basis through a odbc connection to a MSSQL database.
Some of these pulls result in 10 million plus records being copied, many of which have previously been imported.
I would like to pull just the previous 31 days of records.
Each record has a date field in the format YYYYMMDD (20140115).
So my question is how can we just grab the most recent 31 days on this date format?

So

SELECT field_names
FROM table_name
WHERE date_field Greater then today-31

Any advise will be welcome.

Was it helpful?

Solution

Use something like:

... WHERE date_field > TODAY - INTERVAL(31) DAY TO DAY

And thanks to ceinmart:

Or like

... WHERE date_field > TODAY - 31
... WHERE date_field > TODAY - 31 units day

or for better treatment by month...

... WHERE date_field > TODAY - 1 units month
... WHERE date_field > TODAY - interval(1) month to month
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top