错误1366 - 十进制值不正确:''表示第-1行的列''

时间:2014-12-10 16:35:45

标签: mysql decimal varchar

我有一个相当大的查询,试图获取运营商列表,并比较他们记录的保险金额,以确定不符合最低门槛的运营商。如果我运行select查询它可以正常工作,没有错误。但是当我尝试将它用于插入表时,它会返回此错误消息

[Err] 1366 - Incorrect decimal value: '' for column '' at row -1

我必须在此查询的底部使用强制转换为十进制,因为存储在数据库中的值是varchar,我无法更改它。

有人有什么想法吗?

set @cw_days = 15;
INSERT INTO carrier_dnl (carrier_id, dnl_reason_id, status_id)
SELECT work_cw_carrier_status_update.carrier_id, company_dnl_schema.dnl_reason_id,
  CASE
    WHEN work_cw_carrier_status_update.comparison_date > @cw_days THEN 1
  ELSE 4
  END as status
  FROM work_cw_carrier_status_update
  JOIN company_dnl_schema
    ON company_dnl_schema.dnl_reason_id = 51
  LEFT OUTER JOIN carrier_insurance
    ON carrier_insurance.carrier_id = work_cw_carrier_status_update.carrier_id
  WHERE ifnull(carrier_insurance.insurance_type_id,4) = 4
    AND date(now()) BETWEEN IFNULL(carrier_insurance.insurance_effective_date,DATE_SUB(now(),INTERVAL 1 day)) AND IFNULL(carrier_insurance.insurance_expiration_date,DATE_ADD(now(),INTERVAL 1 day))
    AND CASE WHEN NULLIF(carrier_insurance.insurance_bipdto_amount,'') is null THEN 0 < company_dnl_schema.value
    ELSE
      ifnull(cast(replace(carrier_insurance.insurance_bipdto_amount, '*','') as decimal),0) < company_dnl_schema.value
    END
    AND ( work_cw_carrier_status_update.b_bulk = 0 OR work_cw_carrier_status_update.b_bulk = 1 )
    AND ( work_cw_carrier_status_update.b_otr = 1 OR work_cw_carrier_status_update.b_ltl = 1
            OR work_cw_carrier_status_update.b_dray = 1 OR work_cw_carrier_status_update.b_rail = 1
            OR work_cw_carrier_status_update.b_intermodal = 1 OR work_cw_carrier_status_update.b_forwarder = 1
            OR work_cw_carrier_status_update.b_broker = 1 )
group by work_cw_carrier_status_update.carrier_id;`

1 个答案:

答案 0 :(得分:1)

如果select似乎有效,那么有两个可能的问题。首先是select并没有真正起作用,问题在数据中显得更低。返回一个或几个行并不总是和#34; work&#34;。

相同

第二种是与插入类型不兼容。您可以尝试使用静默转换将select中的值转换为数字:

SELECT work_cw_carrier_status_update.carrier_id + 0, company_dnl_schema.dnl_reason_id + 0,
       (CASE WHEN work_cw_carrier_status_update.comparison_date > @cw_days THEN 1
             ELSE 4
        END) as status

这可能看起来很丑陋,但它并不像在一个表中将ID存储为字符串而在另一个表中存储数字一样丑陋。