Knowledgebase
[QODBC-Desktop] Troubleshooting - Getting Unexpected extra token error in Date Field Query
Posted by Jack - QODBC Support on 11 January 2016 10:28 AM

Troubleshooting - Getting Unexpected extra token error in Date Field Query

Problem Description:

I am trying to query the Transaction table based on the TxnDate field.

I tried the below code.

OdbcCommand SourceCmd = new OdbcCommand("Select * from Transaction where TxnDate >= {d '2010-01-01'} and TxnDate <= {d '" + DateTime.Now.ToString("yyyy-MM-dd") + "'} ", cnQODBC);

I am getting this error:

ERROR [42000] [QODBC] [sql syntax error] Expected lexical element not found: =

And when I try this one:

OdbcCommand SourceCmd = new OdbcCommand("Select * from Transaction where TxnDate >= #2010-01-01# and TxnDate <= #" + DateTime.Now.ToString("yyyy-MM-dd") + "# ", cnQODBC);

I get this error:

ERROR [42000] [QODBC] Unexpected extra token: #

What is the correct format to pass the date values ??

I am using C#.

Solution:

Please refer to the below-mentioned article for the date format in QODBC:
How are dates formatted in SQL queries when using the QuickBooks-generated timestamps

(2 vote(s))
Helpful
Not helpful

Comments (2)
Jeff Meyer
15 January 2016 08:51 PM
[QODBC] [sql syntax error] Expected lexical element not found: = )
WTF? not a helpful error at all. Which lexical element? What is a lexical element? What was the value that caused the error? For $199 I expect useful error messages from QODBC.
Jack
18 January 2016 07:45 AM
Hi,

For Lexical element error, Please refer below mentioned link:
http://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2465
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).