在 CTE 中选择时从字符串转换日期和/或时间时转换失败
我有一个问题。我不断收到错误
CASE WHEN j.PHPPDT = '00010101' THEN '0' ELSE j.PHPPDT END AS NEWPPDT,
CASE WHEN j.PHPDTE = '00010101' THEN '0' ELSE j.PHPDTE END AS NEWPROMDT
列 j.PHPPDT
和 j.PHPDTE
的数据类型为 DATE
。
当我只运行它们时,代码似乎可以运行。然而,后来我用我的代码创建了另一个 CTE 并需要选择它们,然后我得到一个错误
NEWPPDT AS PrintersPortDate,
NEWPROMDT AS PromiseByDate,
错误是:
从字符串转换日期和/或时间时转换失败。
我不太确定在哪里以及如何修复它,因为通常当发生这种情况时我只是使用
WHERE CONVERT(DATE, CONVERT(CHAR(8), NEWPPDT ))
,但在这里它没有帮助。此外,我不确定我是否明白该将其插入哪里。我应该在我的 case 语句中或在选择列时将其插入到 j.PHPPDT
中吗...
这非常令人困惑。有人知道什么可能有帮助吗?
I have a question. I keep getting an error
CASE WHEN j.PHPPDT = '00010101' THEN '0' ELSE j.PHPPDT END AS NEWPPDT,
CASE WHEN j.PHPDTE = '00010101' THEN '0' ELSE j.PHPDTE END AS NEWPROMDT
Columns j.PHPPDT
and j.PHPDTE
are of datatype DATE
.
When I run just them, the code seems to run. However, later with my code I create another CTE and need to select them and then I get a mistake
NEWPPDT AS PrintersPortDate,
NEWPROMDT AS PromiseByDate,
The error is:
Conversion failed when converting date and/or time from character string.
I am not really sure where and how to fix it, because normally when such things happen I just use
WHERE CONVERT(DATE, CONVERT(CHAR(8), NEWPPDT ))
but here it doesn't help. Further, I am not sure I understand where to even insert it. Should I insert it to j.PHPPDT
in my case statement or when I select the column...
It is pretty confusing. Does someone know what might help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用一些默认日期值而不是“0”
You can try using some default date value instead of '0'