Acho que esse meu exemplo aqui pode te ajudar

public function fetchMenuArray()
    {
        $sql  = 'SELECT CodigoID, @r:=@r+1 AS id, Nome as title, Ordem as
"order", Label as label, ';
        $sql .= 'IF(CodigoID=1, 1, 0) AS active, ';
        $sql .= 'Ativo as visible, Class as class, Route as route, MenuID,
';
        $sql .= '(SELECT usuario_recurso.Nome FROM usuario_recurso WHERE
RecursoID = usuario_recurso.CodigoID) AS resource ';
        $sql .= 'FROM menu, (SELECT @r:=0) X ORDER BY Ordem ASC';
        $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
        $stmt->execute();
        $menuItens = $stmt->fetchAll();
        $menus = $this->formatTree($menuItens, null);
        return $menus;
    }


Em 3 de fevereiro de 2014 18:23, marceloleob <[email protected]>escreveu:

>
> Olá galera, tudo bem?
>
> Gostaria de saber se alguém já teve problemas com o *PERIOD_DIFF* e como
> fez para resolver.
>
> Estou utilizando o *Doctrine 2* e já procurei muito uma possível solução
> mas ainda não encontrei.
>
> O SQL "puro" seria o seguinte..
>
> SELECT    SUM(PERIOD_DIFF(DATE_FORMAT(dtFim, '%Y%m'), DATE_FORMAT(dtInicio, 
> '%Y%m'))) AS totalMesFROM    bolsistaWHERE    tipobolsa_id = 5 AND    
> pessoa_id = 42ORDER BY    id;
>
>
> Como faço isso no Doctrine?
>
>
> $qBuilder = $this->getEntityManager()->createQueryBuilder();
>
> $qBuilder->select(
>
>     $qBuilder->expr()->literal('SUM(PERIOD_DIFF(DATE_FORMAT(q.dtFim, 
> \'%Y%m\'), DATE_FORMAT(q.dtInicio, \'%Y%m\'))) AS totalMes')
> )
> ->from($this->getEntityName(), 'q')
> ->where('q.pessoa = :pessoa')
> ->andWhere('q.ativo = :ativo')
> ->andWhere('q.tipoBolsa = :tipoBolsa')
> ->setParameter('pessoa', $pessoaId)
> ->setParameter('tipoBolsa', $tipoBolsa)
> ->setParameter('ativo', 1)
> ->orderBy('q.id', 'ASC');
>
>
>
> Óbvio que não deu certo, se não eu não estaria postando aqui..
>
>
>
> Agradeço se alguém me der uma luz!
>
>
> :)
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
________________________________
       Isaac Henrique Barbosa Nunes
  Analista e Desenvolvedor de Sistema

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to