将NULL值以日期时间格式更改为空字符串 [英] Change NULL values in Datetime format to empty string

查看:649
本文介绍了将NULL值以日期时间格式更改为空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含'NULL'值的表,它们是'datetime'类型。现在我必须将它们转换成空字符串,但是当我使用转换函数时,

  ISNULL([应计出默认值] ')

这里累积的默认值是datetime类型,它的作用是将null更改为'1900- 01-01 00:00:00.000'而不是空



然后我尝试将它们转换成varchar并应用相同的

  ISNULL(CONVERT(varchar(50),[Amort Into Default]),'')

现在我可以转换为空字符串,但现在这些datetime转换为字符串,我需要在datetime
所以我尝试CAST,CONVERT,但不工作。 / p>

  CONVERT(Datetime,'ISNULL(CONVERT(varchar(50),[Amort Into Default]),'')',120 )

这给出错误。



是有任何可能的解决方案。

 >解决方案你好有人回答这个做。 
> ISNULL(CONVERT(varchar(50),[Amort Into Default],120),''),它的作品我不知道为什么。

**

解决方案

CASE和CAST应该工作:

  CASE WHEN mycol IS NULL THEN''ELSE CONVERT(varchar(50 ),mycol,121)END 


I have a table which contains 'NULL' values which are of type 'Datetime'. Now i have to convert those into empty string but when when i use convert function

ISNULL( [Accrued Out of Default] ,'' )

here accrued into default is of datetime type, what it does it changes null to '1900-01-01 00:00:00.000' instead of empty

Then i try to convert them into varchar and apply same

ISNULL(CONVERT(varchar(50),  [Amort Into Default] ),'')

Now I am able to convert into empty string but now those datetime are converted to string which I needed in datetime So I try to CAST, CONVERT but non of them works.

CONVERT(Datetime,'ISNULL(CONVERT(varchar(50),  [Amort Into Default] ),'')',120)

This gives error.

Is there any possible solution to this.

> **Solution Hi someone answered this to do as.
>      ISNULL(CONVERT(varchar(50),  [Amort Into Default] ,120),'') and it works  I dont know why .

**

解决方案

CASE and CAST should work:

CASE WHEN mycol IS NULL THEN '' ELSE CONVERT(varchar(50), mycol, 121) END

这篇关于将NULL值以日期时间格式更改为空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆