美好的一天,大家!
我有以下Doctrine查询来检索一些CTI实体:
SELECT s.id
FROM CRM\SpendBundle\Entity\Spend s
WHERE (CASE
WHEN s INSTANCE OF 'CRM\BusinessTripBundle\Entity\BusinessTrip' THEN 'Business Trip'
WHEN s INSTANCE OF 'CRM\ExpenseRequestBundle\Entity\ExpenseRequest' THEN 'Expense Request'
ELSE '' END) IN(:availableSpends)
参数availableSpends只是一个字符串数组:
availableSpends = array('Expense Request')
此查询会抛出错误:
[Syntax Error] line 0, col 439: Error: Expected =, <, <=, <>, >, >=, !=, got 'IN'
如何使用CASE语句来避免此错误? Doctrine版本是2.5.1
答案 0 :(得分:0)
您可以重写该语句,以防它不能与您合作,如下所示:
SELECT s.id
FROM CRM\SpendBundle\Entity\Spend s
WHERE (s INSTANCE OF 'CRM\BusinessTripBundle\Entity\BusinessTrip' and 'Business Trip' IN (:availableSpends))
or (s INSTANCE OF 'CRM\ExpenseRequestBundle\Entity\ExpenseRequest' and 'Expense Request' IN (:availableSpends))