我正在尝试将存储为VARCHAR的所有值转换为正确的列类型的数据库,例如:INT,DATE,DECIMAL等......
问题是,date_order
,date_billed
和date_paid
列以不同格式存储
我仍然会收到1292 Truncated incorrect date value: '05/18/2011'
错误,并且几乎不知道该怎么做,因为确切的日期格式列为CASE
我的代码:
SELECT
CAST(`ar_no` AS UNSIGNED),
CAST(`accession_id` AS UNSIGNED),
CAST(`client_id` AS UNSIGNED),
CAST(`insurance_id` AS UNSIGNED),
CAST(`test_id` AS UNSIGNED),
CASE
WHEN `date_paid` = '0' THEN `date_paid` = '00/00/0000'
WHEN LENGTH(DATE(STR_TO_DATE(`date_order`, '%m/%d/%y'))) IS NOT NULL THEN STR_TO_DATE(`date_order`, '%m/%d/%y')
WHEN LENGTH(DATE(STR_TO_DATE(`date_order`, '%m/%d/%Y'))) IS NOT NULL THEN STR_TO_DATE(`date_order`, '%m/%d/%Y')
END,
CASE
WHEN `date_paid` = '0' THEN `date_paid` = '00/00/0000'
WHEN LENGTH(DATE(STR_TO_DATE(`date_billed`, '%m/%d/%y'))) IS NOT NULL THEN STR_TO_DATE(`date_billed`, '%m/%d/%y')
WHEN LENGTH(DATE(STR_TO_DATE(`date_billed`, '%m/%d/%Y'))) IS NOT NULL THEN STR_TO_DATE(`date_billed`, '%m/%d/%Y')
END,
CASE
WHEN `date_paid` = '0' THEN `date_paid` = '00/00/0000'
WHEN LENGTH(DATE(STR_TO_DATE(`date_paid`, '%m/%d/%y'))) IS NOT NULL THEN STR_TO_DATE(`date_paid`, '%m/%d/%y')
WHEN LENGTH(DATE(STR_TO_DATE(`date_paid`, '%m/%d/%Y'))) IS NOT NULL THEN STR_TO_DATE(`date_paid`, '%m/%d/%Y')
END,
CAST(`amount_billed` AS DECIMAL(15,2)),
CAST(`amount_received` AS DECIMAL(15,2)),
CAST(`amount_adjusted` AS DECIMAL(15,2))
FROM `acs`.`billing_unformatted`;
答案 0 :(得分:0)
Mysql仅以YYYY-MM-DD
格式排除日期。这就是您遇到1292 Truncated incorrect date value: '05/18/2011'
您可以在导入之前在Excel中更改此内容。
要更改excel中的日期格式:右键单击顶部单元格。从下拉列表中选择format cells
。将local
更改为'Afrikans'
之类的内容。选择看起来像2001-03-14
的格式。使用顶部单元格fill down
。然后保存文档。
快速说明:Excel有时会尝试执行太多操作,并会将此列还原为English(U.S)
默认时区。因此,如果您计划进行更多编辑,请确保该列未还原。
以下是dev.mysql上更多字符串文字的链接。
此存储过程和帖子也可能对您有所帮助:Error code 1292