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 : Date SQLSearch Forum

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

 New Topic 
 
 Post Reply 
[1]  
 Date SQL 
 Author   Message 
  Matt 
  
 Group: Members 
 Posts: 25 
 Joined: 2006-04-25 
 Profile
 Posted : 2006-05-04 05:40:05
I am switching my database over to pass through queries instead of the slower datasheet method I had been using. It runs quite fast even in unoptimized mode when I filter the dates for the past few days. I only need the records from at most the past 10 days. Is there an SQL line I can write that would give me the records for [Today-10] instead of using Txndate >= {d '2006-04-15'}. I don't want to have to keep on changing that date every few days. Thanks for all your help! 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-05-04 08:26:34

In QODBC, the function CURDATE() – Returns the current computer system date as a date value.

For example, for Today, April 18, 2006, when the following query :-

SELECT {fn CURDATE()} as Today, ({fn CURDATE()}-30) as "30 Days Ago",
TxnDate, RefNumber, InvoiceLineDesc
FROM invoiceline WHERE TxnDate >= ({fn CURDATE()}-30)

is run in VB Demo the results were:

See: What Time and Date Functions can be used with QODBC? for more.

 

  Top 
  Matt 
  
 Group: Members 
 Posts: 25 
 Joined: 2006-04-25 
 Profile
 Posted : 2006-05-06 04:05:03

Ok, I tried that, and it looks like it's trying to load every record instead of limiting it to that date range. Here is my SQL: select {fn CURDATE()} as Today, ({fn CURDATE()}-15) as "15 Days Ago",  ShipDate, CustomerRefFullName, ShipAddressCity, PONumber, InvoiceLineQuantity, InvoiceLineItemRefFullName, InvoiceLineDesc, TemplateRefFullName, RefNumber, IsPending from invoiceLine unoptimized WHERE Txndate >= ({fn CURDATE()}-15)

Anything I can change to make it run as fast as it does when the SQL is like    Txndate >= {d '2006-04-25'} ?

Thanks

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-05-06 16:54:55

Sure, you can use "TxnDateMacro" like this:-

select {fn CURDATE()} as Today, ({fn CURDATE()}-15) as "15 Days Ago",  ShipDate, CustomerRefFullName, ShipAddressCity, PONumber, InvoiceLineQuantity, InvoiceLineItemRefFullName, InvoiceLineDesc, TemplateRefFullName, RefNumber, IsPending from invoiceLine unoptimized WHERE TxnDateMacro='ThisMonthtoDate'

Use the pulldown to see what other values are available for you to use:-

DateMacro =

 

  Top 
  Matt 
  
 Group: Members 
 Posts: 25 
 Joined: 2006-04-25 
 Profile
 Posted : 2006-05-09 01:45:10

Ok, I tried that, and it still doesn't work. I have the optimizer status window enabled and it's trying to go through all 23,000 records in the invoiceline table instead of the 300 I need for Today-15. Again, my goal is to be able to access the records for the past 15 days as fast as possible. It works really well when I do something like Txndate >= {d '2006-04-25'}. But, I would need to change the date every few days to keep the speed fast. I need to always be able to have the past 15 days available.

When I use this SQL, it wants to run all 23,000 records:

select {fn CURDATE()} as Today, ({fn CURDATE()}-15) as "15 Days Ago",  ShipDate, CustomerRefFullName, ShipAddressCity, PONumber, InvoiceLineQuantity, InvoiceLineItemRefFullName, InvoiceLineDesc, TemplateRefFullName, RefNumber, IsPending from invoiceLine unoptimized WHERE TxnDateMacro='Today-15'

Any ideas? Thanks!

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-05-09 07:41:05
This is normal bahaviour, a literal is faster as it can use a QODBC jump-in, while an evaluated value needs to be tested against each record. What should be actually done is to generate the SQL statement via a program with the dates required as literals. 

  Top 
  Matt 
  
 Group: Members 
 Posts: 25 
 Joined: 2006-04-25 
 Profile
 Posted : 2006-05-09 08:23:53
How do I do that? 

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

In Access you would create an Unbound Form and use the On Load event procedure to call the function uf_DisplayRecord that would contain the VBA of a select statement that would generate the date value literals based on the system date - 15.

Books like the Access 2003 Bible found on Amazon outline the procedure.

Access 2003 Bible -- by Cary N. Prague

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to