Zen Cart Logo
Forums / General Questions / Need to get all orders in a date range by sql

Need to get all orders in a date range by sql

Views: 1,265

Results 1 to 13 of 13
23 May 2013, 3:22 PM
#1
navido avatar

navido

Zen Follower

Join Date:
Sep 2008
Posts:
221
Plugin Contributions:
0

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

23 May 2013, 3:25 PM
#2
g2ktcf avatar

g2ktcf

Totally Zenned

Join Date:
Feb 2011
Location:
Lumberton, TX
Posts:
636
Plugin Contributions:
0

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

navido:

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......

23 May 2013, 3:28 PM
#3
g2ktcf avatar

g2ktcf

Totally Zenned

Join Date:
Feb 2011
Location:
Lumberton, TX
Posts:
636
Plugin Contributions:
0

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.

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');
23 May 2013, 3:51 PM
#4
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

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

try this:

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

23 May 2013, 5:50 PM
#5
navido avatar

navido

Zen Follower

Join Date:
Sep 2008
Posts:
221
Plugin Contributions:
0

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

Attachment 12539

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?

23 May 2013, 6:08 PM
#6
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

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:

SELECT [B]`[/B]orders_id[B]`[/B],`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

23 May 2013, 6:16 PM
#7
navido avatar

navido

Zen Follower

Join Date:
Sep 2008
Posts:
221
Plugin Contributions:
0

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

Thanks

How about the Autosum. Any idea?

23 May 2013, 6:19 PM
#8
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

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.

23 May 2013, 6:31 PM
#9
navido avatar

navido

Zen Follower

Join Date:
Sep 2008
Posts:
221
Plugin Contributions:
0

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/windows-platform/articles/10782.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.

23 May 2013, 6:34 PM
#10
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

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.

23 May 2013, 6:37 PM
#11
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

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

you could always try to re-format the cells in excel (right click, format cells, then under the "number" tab, select number or currency). might work, but I feel like these are hoops you shouldn't need to jump through. at least I've never had to....

23 May 2013, 6:47 PM
#12
navido avatar

navido

Zen Follower

Join Date:
Sep 2008
Posts:
221
Plugin Contributions:
0

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

No you misunderstand, the problem is when i export it to CSV, not CSV for MS Excel

23 May 2013, 7:11 PM
#13
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,701
Plugin Contributions:
56

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

Instead of using phpMyAdmin, why not try Sales Report (in the Plugins at the top of the page). It does date based reporting and should give you what you need.