如果日期值为空,则将日期时间转换为字符串-保持原始日期时间格式 [英] CASTing a datetime to string if null value - keeping original datetime formatting
本文介绍了如果日期值为空,则将日期时间转换为字符串-保持原始日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的查询包含以下部分:
I have the following part of my query:
ISNULL(cast(fd.decision_date as varchar(20)), 'PENDING') as facility,
ISNULL(cast(cd.decision_date as varchar(20)), 'PENDING') as corporate,
ISNULL(cast(cb.creation_date as varchar(20)), 'PENDING') as billing
我的值最初是datetime数据类型,但我想做的是
My values are originally of datetime datatype, but what I want to do is return the word 'PENDING' if the value is NULL.
使用上面的代码,我的结果被 cast
ed了到 varchar
,因此返回以下内容:
With the code above, my results are cast
ed to a varchar
, thus returning something like:
Aug 20 2013 9:35AM
而不是 2013-08-20 09:35:54
建议将不胜感激。
推荐答案
用转换
和适当的 style 替换 cast
:转换语法&样式,例如:
Replace cast
with convert
and appropriate style: Convert syntax & styles, eg:
ISNULL(convert(varchar(20), fd.decision_date, 120), 'PENDING') as facility,
这篇关于如果日期值为空,则将日期时间转换为字符串-保持原始日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文