Search code examples
phpmysqlsqldrupaldrush

Sql error "Syntax error or access violation: 1064"


getting (syntax error or access violation 1064) dont know what is the problem. why i am getting this error? I think problen in my syntax with DATE

here is the screen with error: enter image description here

My code:

$sql = "SELECT ds.id
FROM documents ds
INNER JOIN institutions_if ib on ds.to_inst_id = ib.id
INNER JOIN documents_log dl on ds.id = dl.doc_id
WHERE
  ds.to_inst_id in :insts
  AND DATE(FROM_UNIXTIME(dl.timestamp)) = '2014-12-31'   //   <======== ERROR HERE!!!!!
  AND ds.status in ('sent','received','accepted','archived')
  AND ds.template_id = :template1
  AND NOT EXISTS (
    SELECT id FROM documents dr
        WHERE
            dr.reply_to = ds.id
            and dr.template_id = :template2
            and dr.status in ('sent','received','accepted','archived')
            and dr.to_inst_id in :insts
        );";

  $result = db_query($sql, array(
    ':insts' => institution_children_plan('[237, 279, 373]'),
    ':template1' => DocumentTemplate::get_template_by_handler('disp_suspend_operat_cont'),
    ':template2' => DocumentTemplate::get_template_by_handler('comun_anul_disp_susp_oper')
  ));

Solution

  • You missed the () around the first IN content

    WHERE   ds.to_inst_id in (:insts)
    

    so you have an error on the next AND