Question : Pervasive SQL 9.5 - odbc SELECT Query - DATE = '0000-00-00'

A software vendor we use at work has recently given me ODBC access to their products database which is Pervasive SQL 9.5 (sp2).  I am working on automating the accounting data transfer from this software to our accounting software, and have hit a wall.

I am using the Pervasive client odbc drivers for 9.50 (sp2), and have tried this from a windows box, and a linux box using unixODBC with the psql linux client.

In the Pervasive db, there is a DATE field in two accounting tables that indicate if an invoice has been transferred (to the other accounting system), or if it is pending transfer.  I am after the ones pending transfer.

When the invoice is transferred the DATE field in the two accounting tables is populated with the date of the transfer.

This is where I have hit the wall.  When the invoice is not transferred the date is 0000-00-00.
I basically need to query the not-transferred invoices in pervasive.
When I try to query the date field = '0000-00-00' is throws an odbc error.  Here is the error:

SQL error: [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Invalid date, time or timestamp value., SQL state 22008 in myfile.name on line number

I Googled this for an hour or two. I found others have had the same issue, but no solutions.

Here is the strange thing:

When I query the pervasive db with a SQL tool or from a php script the field shows a value of
0000-00-00 for not-transferred invoices.

When I go the the actual pervassive ODBC engine server, and look at this field using the PervasiveSQL Control Center application, it displays the not-transferred invoices with a date as:
11/30/0002

I have tried to query the not-transferred invoices using all kinds of combos to no avail.

SELECT * from TABLE WHERE FIELD = '0000-00-00'

SELECT * from TABLE WHERE FIELD = '0002-11-30'

SELECT * from TABLE WHERE FIELD is NULL

SELECT * from TABLE WHERE FIELD = {d  '0000-00-00'}

SELECT * from TABLE WHERE FIELD = {d  '0002-11-30'}

There were probably more SQL query combos, but none worked.  They either threw an odbc error complaining about the date format in the query, or the worked with now results.

Does anyone know of a sneaky way around this 0000-00-00 issue?  Is there such a thing as SELECT * FROM TABLE WHERE FIELD is not a DATE, or any other option?

I am really trying to get this working without having to contact the software vendor.  They were reluctant to give me the odbc, and stress that they do not support it. I am ok with that.  However, if there is no work around for the 0000-00-00 issue, I guess I could ask them to make a change to there software to populate the not-transferred fields with a bogus date (1234-01-01) or something?

Any thoughts, or ideas would be great!

Thanks!
Bob

Answer : Pervasive SQL 9.5 - odbc SELECT Query - DATE = '0000-00-00'

What's probably happening is that the date is being populated through the Btrieve interface with spaces instead of a valid value.  The value 00-00-0000 is invalid according to the ODBC Specifications.  

The proper solution to this problem is to get the software vendor to put a valid date or null for this non-transferred field.  

You might try converting the date to a string and seeing if you can restrict that way.  For example, SELECT * FROM TABLE WHERE CONVERT(FIELD, SQL_CHAR) = '      ' where the value between single quotes is 6 spaces.  You might have to try different values to see what works.
Random Solutions  
 
programming4us programming4us