Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : Trouble using TIMESTAMPADD in Where clause of a query to InvoicesSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Sample Scripts Forum

 New Topic 
 
 Post Reply 
[1]  
 Trouble using TIMESTAMPADD in Where clause of a query to Invoices 
 Author   Message 
  Ken Brey 
  
 Group: Members 
 Posts: 9 
 Joined: 2008-02-09 
 Profile
 Posted : 2008-05-08 08:03:58
I am having trouble using the TIMESTAMPADD function in a query against the Invoice table.  The following statement doesn't work:

select top 10 TxnDate, SubTotal from Invoice  NOSYNC Where TxnDate>={d'2007-07-01'} and TxnDate < { fn TIMESTAMPADD(SQL_TSI_MONTH,-1, {fn CURDATE()} )}

The error I get is:   [QODBC] Invalid Operand for operator: <

However, the following similar statements do work:

SELECT top 10 TimeCreated from Customer NOSYNC where TimeCreated < {fn TIMESTAMPADD(SQL_TSI_MONTH,-1,  {fn CURDATE()}  )}

SELECT top 10 TxnDate, SubTotal from Invoice NOSYNC Where TxnDate >={d'2007-07-01'} and TxnDate < {fn CURDATE()}

So why would the addition of the TIMESTAMPADD function not work in a query to Invoice when the same clause works in a query to Customer? 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-05-08 08:30:54

That's because TxnDate is a Date, while TimeCreated is a Timestamp.The TIMESTAMPADD function can't be used with dates.

See: How are dates formatted in SQL queries when using the QuickBooks generated time stamps? for more.

 

  Top 
  Ken Brey 
  
 Group: Members 
 Posts: 9 
 Joined: 2008-02-09 
 Profile
 Posted : 2008-05-09 03:11:07
When I use date functions in the WHERE clause my query takes much longer than when I use a constant.  I believe that it is doing a full table-scan instead of an indexed search.

The following statement takes 6 minutes to execute:

select TxnDate,SubTotal from Invoice NOSYNC
    where TxnDate> {fn CONVERT( {fn TIMESTAMPADD(SQL_TSI_MONTH,-8, {fn CURDATE()} )}, SQL_DATE)}

However, this statement only takes 38 seconds:

select TxnDate,SubTotal from Invoice NOSYNC
    where TxnDate> {d'2007-09-08'}

How can I get performance like the first statement using date functions?  I am performing this query through an OpenQuery statement in SQL Server.  I can't do the string manipulation in SQL Server because "OPENQUERY does not accept variables for its arguments".   ( http://msdn.microsoft.com/en-us/library/ms188427.aspx ) 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-05-09 07:45:08

That's correct, functions need to be evaluated during execution while constants are loaded prior to execution. You can try forcing the evaluation on a subset first like this:-

select {fn Curtime()}, TxnDate,SubTotal from Invoice NOSYNC
    where TxnDate> {d'2007-08-01'}
    and TxnDate> {fn CONVERT( {fn TIMESTAMPADD(SQL_TSI_MONTH,-8, {fn CURDATE()} )}, SQL_DATE)}

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to