如何解决在空日期不支持从int转换为DATE
| 我相信这是SQL 2000/2005中的错误/问题...如果我的结果在DATETIME列上为null,我会得到com.microsoft.sqlserver.jdbc.sqlserverexception:
the conversion from int to date is unsupported
当我用sql.getDate(\"ColumnName\")
...
有什么解决办法吗?
[编辑]
大家好,谢谢您的输入,以下是我的SQL查询
select p.planno as PlanNumber,t.TrancheID as TrancheID,t.tranchestartdate as TrancheStartDate,t.tranchereasoncode as TrancheReasonCode,ai.ArrayItemDecode TrancheReasonDescription,t.trancheuwstage as UnderwritingStatusCode
from plan_ p
inner join tranche t
on t.planno = p.planno
and t.trancheuwstage in ( 2,4 )
and p.planno = \'040000000X6\'
inner join arrayitem ai
on ai.ArrayNm = \'arrTraReas\'
and ai.ArrayItemCode = t.tranchereasoncode;
罪魁祸首是tranchestartdate,它是DATETIME。我真的无法在表格中添加任何内容,因为不允许更改现有的表结构,这是一个很大的系统。也许我可以在SQL中进行转换?我不太确定这是否绝对是空问题。可以在我调用getDate()之前调试/监视ResultSet并检查是否检索到任何数据吗?
[/ EIDT]
解决方法
如果您的应用程序(或驱动程序)无法处理空日期,那么最简单的方法可能是使用ISNULL(field,<空替换日期>)并在代码中检查空替换日期。此方法使用幻数(日期)来表示空值true。它虽然不漂亮,但快速而直接。
,您不能为此使用合并吗?
http://msdn.microsoft.com/en-us/library/ms190349.aspx
,您是从字段中选择日期时间还是在
SELECT
中动态构建日期时间?您可能必须将结果加4。
看这篇文章
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。