Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

SQL select with CASE / WHEN
 
Rool
Member
 
Total Posts:  36
Joined:  2008-09-03
 

hi,

i am trying to add another coloumn to the sales/order grid.
i need to compare the “grand_total” and “total_paid” fields. i think i should do that with a sql CASE:

CASE paid WHEN total_paid = 0 THEN ‘notpaid’ WHEN grand_total> total_paid THEN ‘halfpaid’ WHEN grand_total = total_paid THEN ‘paid’

or something like that. but which command do i have to use?
joinAttribute ? joinField ? where can i put my sql command?

thanks for any hints!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rool
Member
 
Total Posts:  36
Joined:  2008-09-03
 

ok, i get it:

->addExpressionAttributeToSelect('paid',
    
"CASE WHEN ({{status}} = 'canceled') THEN '' WHEN ({{total_paid}} = 0) THEN 'no' WHEN ({{total_paid}}<{{grand_total}}) THEN 'half' WHEN ({{total_paid}}>{{grand_total}}) THEN 'over' ELSE 'yes' END",
    array(
'grand_total''total_paid','status'))
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top