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
|
|
Trouble using TIMESTAMPADD in Where clause of a query to Invoices |
Author |
Message |
|
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? |
|
|
|
Tom |
|
Group | : Administrator |
Posts | : 5510 |
Joined | : 2006-02-17 |
|
Profile |
|
Posted : 2008-05-08 08:30:54 |
|
|
|
|
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 ) |
|
|
|
Tom |
|
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)} |
|
|
|
|