Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Sep 2008
    Posts
    220
    Plugin Contributions
    0

    Default Need to get all orders in a date range by sql

    Hi

    From phpadmin i try to get all orders (only some columns) from the table orders.

    I need to get a list for march 2013

    This is what i have tried (this is just an example i tried for 2011):

    SELECT 'orders_id',`customers_name`,`order_total`,`payment_method` FROM 'orders' WHERE 'date_purchased' BETWEEN '2011-02-01' and '2011-02-01';

    But i get en error.

    Can anyone show me the code i have to use?

    Thanks

  2. #2
    Join Date
    Feb 2011
    Location
    Lumberton, TX
    Posts
    557
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    Quote Originally Posted by navido View Post
    Hi

    From phpadmin i try to get all orders (only some columns) from the table orders.

    I need to get a list for march 2013

    This is what i have tried (this is just an example i tried for 2011):

    SELECT 'orders_id',`customers_name`,`order_total`,`payment_method` FROM 'orders' WHERE 'date_purchased' BETWEEN '2011-02-01' and '2011-02-01';

    But i get en error.

    Can anyone show me the code i have to use?

    Thanks

    Well it would be helpful to know what the error is......

  3. #3
    Join Date
    Feb 2011
    Location
    Lumberton, TX
    Posts
    557
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    your dates not dates but text from the why I see it....look at this example.

    Code:
    SELECT *
    FROM orders
    WHERE order_date >= to_date('2003/01/01', 'yyyy/mm/dd')
    AND order_date <= to_date('2003/12/31','yyyy/mm/dd');

  4. #4
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    try this:

    Code:
    SELECT 'orders_id',`customers_name`,`order_total`,`payment_method`, `date_purchased` FROM orders WHERE date_purchased BETWEEN "2013-03-01" AND "2013-03-30"
    ps - looks like you just had regular single-quotes (') around the table name instead of back-quotes (`) which was throwing the error
    Last edited by jc8125; 23 May 2013 at 04:55 PM. Reason: add'l info

  5. #5
    Join Date
    Sep 2008
    Posts
    220
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    Thanks for each one of you.

    jc8125:

    It worked, however two things

    I exported to "CSV for MS excel" and the "orders_id" doesnt show up with the ordernumber, but the text "orders_id". See the picture below

    Name:  orders_Id.jpg
Views: 113
Size:  12.0 KB

    Also when try to use the Autosum in excel, it does not summarize the orders total column. It just shows 0. This is because it doesnt recognize is as integer or number. How to solve this?

  6. #6
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    doh! I copied your original code, which had the incorrect quotes around the orders_id field, try this:

    Code:
    SELECT `orders_id`,`customers_name`,`order_total`,`payment_method`, `date_purchased` FROM orders WHERE date_purchased BETWEEN "2013-03-01" AND "2013-03-30"
    not sure about the autosum issue.. I don't export as CSV for Excel - so can't provide much help. I just tested using the "export as csv" and it works fine, and autosums things correctly (in excel). might want to use that method
    Last edited by jc8125; 23 May 2013 at 07:11 PM. Reason: more

  7. #7
    Join Date
    Sep 2008
    Posts
    220
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    Thanks

    How about the Autosum. Any idea?

  8. #8
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    you might not have seen the edited part of my post, seems to work when exporting as csv (as opposed to csv for excel). not sure what exactly the difference is, probably adds some goofy microsoft formatting. i would just use the plain csv unless you have a reason otherwise.

  9. #9
    Join Date
    Sep 2008
    Posts
    220
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    Yes i managed to get it work with CSV by following this step:
    http://www.brighthub.com/computing/w...82.aspx#imgn_0

    However the column which contains the total "order total" does not get summarized. It just shows 0 when i use the autosum.

  10. #10
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default Re: Need to get all orders in a date range by sql

    not sure.. when i export as "csv for excel", i have to go through the text-to-columns steps you referenced. however, when i export as plain old csv, it opens up fine in excel, already split into columns correctly, and the total/sum works fine on the order totals. not sure what to tell ya.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Need an SQL query to select a range of products and update the product status to 0
    By oztraveller06 in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 8 Mar 2014, 07:33 AM
  2. v150 Remove ALL customers and ALL orders before a certain date and reset counter history.
    By hawkwynd in forum Managing Customers and Orders
    Replies: 4
    Last Post: 10 Dec 2013, 03:22 AM
  3. Need help to SQL change the Product Add Date
    By explorer1979 in forum General Questions
    Replies: 2
    Last Post: 1 Sep 2012, 03:22 PM
  4. HELP! All Orders Get Stuck
    By Pammydee in forum Managing Customers and Orders
    Replies: 17
    Last Post: 25 Jun 2006, 04:30 AM
  5. SQL Error 1264 Out of range value adjusted
    By NACServices in forum Setting Up Categories, Products, Attributes
    Replies: 7
    Last Post: 25 May 2006, 01:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR