Double-up the parentheses:

$this->Something->find('all', array(
  'fields' => array(
    'Something.id',
    '((CASE WHEN Something.id%2=0 THEN \'even\' ELSE \'odd\' END)) AS
parity'
  )
));

Works fine on my (almost latest) build [and has done for a while -
I've used this before]

hth
grigri

On Oct 15, 3:34 pm, MarcS <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I'm trying to figure out how I can use the CASE WHEN function with
> cakephp
>
> I'm trying to run the following query
> SELECT `type` , (
>
> CASE
> WHEN `type` = 'type3'
> THEN 1
> WHEN `type` = ''type4'
> THEN 2
> WHEN `type` = ''type1'
> THEN 3
> ELSE 4
> END
> ) AS sort
> FROM `task_lines` AS `TaskLine`
> ORDER BY `sort` ASC
>
> This is the Cake statement which I've tried:
> $this->TaskLine->find('all',array('fields' => array('type',"(
> CASE
> WHEN `type` = 'type3'
> THEN 1
> WHEN `type` = ''type4'
> THEN 2
> WHEN `type` = ''type1'
> THEN 3
> ELSE 4
>                 END
>                 ) AS sort"),'order' => 'sort'));
>
> Cake generates the following query:
>
> SELECT `TaskLine`.`type`, `TaskLine`.`( CASE WHEN `type` = 'type3'
> THEN 1 WHEN `type` = 'type4' THEN 2 WHEN `type` = 'type1' THEN 3 ELSE
> 4 END )` AS `sort` FROM `task_lines` AS `TaskLine` WHERE 1 = 1 ORDER
> BY `sort` ASC
>
> which will obviously result in an SQL error.
>
> Any ideas on how to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to