2

How to use expressions in a collection.

More specific, I want to SELECT CAST(qty_shipped AS UNSIGNED).

I have tried something like this: addExpressionFieldToSelect('qty_shipped','CAST(qty_shipped AS UNSIGNED)',null) , but it appends the table name for some reason.

Thanks.

benmarks
  • 23,384
  • 1
  • 62
  • 84
user635818
  • 99
  • 2
  • 9

1 Answers1

10

Try as:

$collection->getSelect()->columns(array('qty_shipped' => new Zend_Db_Expr ('CAST(qty_shipped AS UNSIGNED)')));


Where $collection = Collection Object

Let me know if that works for you.

MagePsycho
  • 1,944
  • 2
  • 29
  • 60