0

In yii, i have a CDbCriteria with select property as:

$criteria->select = "IFNULL(t.cccid,'Default')";

That is I want to return 'Default' if t.cccid is NULL. Else value of t.cccid should be returned/

The problem is that IFNULL is not being recognized. I get error as:

trying to select an invalid column "'Default')"

I have also tried:

$criteria->select = "IFNULL(t.cccid,'Default') as cccid";

and then i get syntax error.

Can anyone help me on how to use IFNULL in $criteria->select?

dInGd0nG
  • 4,162
  • 1
  • 24
  • 37
Mahesh
  • 603
  • 1
  • 10
  • 22

1 Answers1

3

Use of CDbExpression would help you here

$criteria->select = new CDbExpression("IFNULL(t.cccid,'Default') cccid");

or (to select * , or other columns, use array )

$criteria->select = array(
        '*', 
        new CDbExpression("IFNULL(t.cccid,'Default') cccid"),
);
SuVeRa
  • 2,784
  • 2
  • 20
  • 27