查询表达式中的Microsoft ODBC Excel驱动程序语法错误(缺少运算符)

时间:2014-06-28 19:03:25

标签: sql excel

我正在使用 XL Report Builder 版本2.1.4并尝试执行以下脚本但是,在查询表达式中不断收到错误“Microsoft ODBC Excel驱动程序语法错误(缺少运算符)”。< / p>

select Bidders.*
From Bidders
where
If :Param1 = 1 Then
    Due > 0 and
    Left(Event,2) <> 12
Else
    Due = 0 and
    Left(Event,2) <> 12
End If
order by
      Name

Param1是一个用户输入参数,可以是“0”或“1”。  有没有人对我错过的算子有任何建议?

1 个答案:

答案 0 :(得分:0)

查询中的if看起来很可疑。尝试将查询编写为:

select Bidders.*
From Bidders
where (:Param1 = 1 and Due > 0 and Left(Event,2) <> 12) or
      (:Param1 <> 1 and Due = 0 and Left(Event,2) <> 12)
order by Name;

您可以将其简化为:

select Bidders.*
From Bidders
where Event not like '12%' and
      ((:Param1 = 1 and Due > 0) or
       (:Param1 <> 1 and Due = 0)
      )
order by Name;