【问题标题】:The data types real and numeric are incompatible in the modulo operator数据类型 real 和 numeric 在模运算符中不兼容
【发布时间】:2015-01-12 11:18:20
【问题描述】:

我有以下 sql 查询:-

select b.LOGTIME, b.beam_current, b.beam_energy,
  case when a.st1_vs1_bag1_onoff=0 and a.logtime=c.logtime then c.st1_vs1_bag1_rb ELSE 0 END as st1_vs1_bag1_rb ,
  CASE when a.st1_vs1_bag2_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag2_rb else '0' END as st1_vs1_bag2_rb ,
  CASE when a.st1_vs1_bag3_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag3_rb else '0' END as st1_vs1_bag3_rb ,
  CASE when a.st1_vs1_bag4_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag4_rb else '0' END as st1_vs1_bag4_rb ,
  CASE when a.st1_vs1_bag5_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag5_rb else '0' END as st1_vs1_bag5_rb ,
  CASE when a.st1_vs1_bag6_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag6_rb else '0' END as st1_vs1_bag6_rb ,
  CASE when a.st1_vs1_bag7_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag7_rb else '0' END as st1_vs1_bag7_rb ,
  CASE when a.st1_vs1_bag8_onoff='0' and a.logtime=c.logtime then c.st1_vs1_bag8_rb else '0' END as st1_vs1_bag8_rb 

from INDUS2_BDS.dbo.DCCT b  INNER JOIN (main_vacuum_analog c inner join main_vacuum_status a on c.logtime=a.logtime) ON a.LOGTIME = b.LOGTIME 
and  b.beam_current LIKE '%0' 
and (cast(b.beam_current as int) % 10.0 <= 0.01 OR b.beam_current % 10.0 >= 9.99)
and (cast(b.beam_current as int) >= 9.99) -- to set the lower limit of 9.99
and (cast(b.beam_current as int) <= 220.01)
and b.logtime between '2014-10-10 07:17:00' and '2014-10-10 08:46:00'

但是当我执行此查询时,我收到以下错误消息

The data types real and numeric are incompatible in the modulo operator.

我该如何解决?我只想显示从 10、20、30 到 220 的 beam_current 附近的值。

【问题讨论】:

    标签: casting sql-server-2012


    【解决方案1】:

    我得到了答案:-

      (cast(cast(b.beam_current as decimal) % 10.0 as real) <= 0.01) 
    and (cast(cast(b.beam_current as decimal)as real) >= 9.99) -- to set the lower limit of 9.99
    and (cast(cast(b.beam_current as decimal)as real) <= 220.10)
     and b.logtime between '2014-10-10 07:17:00' and '2014-10-10 08:46:00'
    

    【讨论】:

    • 但现在我想要最接近的值,该怎么做??
    猜你喜欢
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多