我无法克服这个错误。
我有一个以mmddyy格式存储的日期字段。
我只想返回日期在2019年12月31日之后的记录。
我知道Pervasive默认使用yyyy-mm-dd。
我正在用下面的代码重新格式化日期:
Convert(Concat('20',Concat(Right(Date,2),Concat('-',Concat(Left(Date,2),Concat('-',Substring(Date)))))),SQL_DATE)日期值081820将返回44061。
Convert('2019-12-31',SQL_DATE)返回43830。
And Convert(Concat('20',Concat(Right(Order_Header.Date_Shipped,2),Concat('-',Concat(Left(Order_Header.Date_Shipped,2),Concat('-',Substring(Order_Header.Date_Shipped,3,2)))))),SQL_DATE) > Convert('2019-12-31',SQL_DATE)返回
[pervasive][ODBC Engine Interface]Invalid date, time or timestamp value我尝试过投射和转换..。有人知道我的And语句(在where子句中)做错了什么吗?或者我如何避免这个错误?
发布于 2020-08-19 04:59:20
您可能具有对数据中的日期无效的值。你最好查查记录。日期规范要求月份为1到12,日期为1到31,具体取决于月份(因此2月30日将无效),年份为0000到9999。像这样几个月,你也会想要检查天数:
insert into sodate (f1) values ('442020');
insert into sodate (f1) values (' 2020');
select f1, left(f1,2) from sodate where left(f1,2) not in ('01','02','03','04','05','06','07','08','09','10','11','12')第一个示例中的substring缺少参数。一旦你得到了正确格式的日期('yyyy-mm-dd'),你应该能够将它与一个日期值进行比较,而无需将其转换为SQL_DATE数据类型。还有一件事,你在所有年份的前面加上了'20‘,如果你的数据是2000年前的,会发生什么?你需要考虑这一点。在PCC中,当我运行:
select Convert('2019-12-31',SQL_DATE)我得到了:
EXPR_1
==========
12/31/2019我使用了下面的语句:
create table sodate (f1 char(6));
insert into sodate (f1) values ('123119');
insert into sodate (f1) values ('081818');
insert into sodate (f1) values ('081820');
insert into sodate (f1) values ('082020');
select * from sodate;
-- This should give the results you want
select concat(concat(concat(concat(concat('20',right(f1, 2)),'-'),left(f1,2)),'-'),substring(f1,3,2)) from sodate where
concat(concat(concat(concat(concat('20',right(f1, 2)),'-'),left(f1,2)),'-'),substring(f1,3,2)) > '2019-12-31';
-- This query shows you don't need the CONVERT to compare a date.
select concat(concat(concat(concat(concat('20',right(f1, 2)),'-'),left(f1,2)),'-'),substring(f1,3,2)) from sodate whereconcat(‘20’,right(f1,2)),'-'),left(f1,2),'-'),substring(f1,3,2)) >= now()
并得到以下结果:
EXPR_1
==============
2019-12-31
2020-08-18 第二个查询给出:
EXPR_1
==============
2020-08-20 https://stackoverflow.com/questions/63476176
复制相似问题