ODBC Excel read returns NULL for dates

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
evangeld
Participant
Posts: 17
Joined: Thu Apr 19, 2012 2:56 pm
Location: Pella
Contact:

ODBC Excel read returns NULL for dates

Post by evangeld »

Interesting problem: Reading an Excel 2003 file via an ODBC connection and noticed that all of my date values were coming in as NULL. I switched to a CSV file using a sequential file input and the dates come in as expected. In either case the text values read fine. Only the dates are corrupted.

Any ideas (other than avoiding all Excel files!)
Evan Van Gelder
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Are you sure they are dates, or string representation of dates?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

ODBC and Excel connections are problematical, at best. ODBC will determine the clumn datatypes dynamically, using the first couple of rows (this number can be adjusted in the ODBC settings). Thus a column that you think holds a date might be delivered to DataStage as a string or a number - and the next run might be sent as a different type.

I've gone the route of explicitly marking and declaring all columns as strings and then done the conversion inside datastage. Or adding 10 or so dummy lines at the beginning with specific values to force the driver to choose the correct datatype and then ignoring those lines in DataStage.
evangeld
Participant
Posts: 17
Joined: Thu Apr 19, 2012 2:56 pm
Location: Pella
Contact:

ODBC Dates

Post by evangeld »

Kryt0n wrote:Are you sure they are dates, or string representation of dates?
They are coming in as strings, but the cells that contain date information are null.
Evan Van Gelder
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Can you see if that changes when you explicitly make strings in the cells, i.e. '="2012-09-12"'?
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Are you getting any dates coming through? Or all dates are being dropped?

As with what ArndW said, are the first few rows actually dates in Excel? If the ODBC driver had determined the column to be date based on the first x rows, any that aren't explicitly dates in Excel will be dropped, whether they look like dates to the eye or not. Really you need to force ODBC to see the column as string/varchar if you have the potential for mixed date/string
evangeld
Participant
Posts: 17
Joined: Thu Apr 19, 2012 2:56 pm
Location: Pella
Contact:

ODBC Excel Dates

Post by evangeld »

That sounds like the problem. The initial rows have NULL values and then there is a block of text strings before any date values appear. Is there a way to force ODBC to view it as strings short of seeding the first several rows?
Evan Van Gelder
evangeld
Participant
Posts: 17
Joined: Thu Apr 19, 2012 2:56 pm
Location: Pella
Contact:

ODBC Excel Dates

Post by evangeld »

ArndW wrote:Can you see if that changes when you explicitly make strings in the cells, i.e. '="2012-09-12"'? ...
When I forced the column to text by inserting a quote ('2012-09-12) The values all flow through as strings and show up. Without the quotes, the date values disappeared.
Evan Van Gelder
Post Reply