我想只存储“ - ”在sql server 2008中的datetime列 [英] I want to store just "-" in datetime column in sql server 2008

查看:62
本文介绍了我想只存储“ - ”在sql server 2008中的datetime列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中使用一个列,它使用格式datetime ...当前一个存储过程更新数据库中的datetime列,其中一些行具有某个日期的值..大多数情况下,这些日期格式与datetiome格式相同价值...像1900-01-01 00:00:00 ...类似的东西,我完全不确定...但相反,那个值..我希望每个值只用 - 代替现在的日期...但由于该列具有日期时间格式...我无法在该值中存储 - ... sql显示错误.. - 不能以日期时间格式存储...有什么方法我可以能够做到这一点?

I am using one column in database which uses format datetime...rightnow one stored procedure updates datetime column in database with some of the rows have values of some date..which is most of the time like in datetiome format and same value ...something like 1900-01-01 00:00:00...something like that i am exactly not sure...but instead that value..i want each value replaced with just"-" instead that date now...but as that column has datetime format ...i am unable to store "-" in that value ...sql shows error..that "-" cant be stored in datetime format..is there any way i can able to do that?

推荐答案

实际上你必须将值保持为NULL并检查你的前端,如果值为NULL则不显示任何内容。 />
如果由于某种原因你不想在列中允许NULL,它将保存01-01-1900然后你检查你的前端,如果值是01-01-1900,没有价值。



或者,在您可以设置的存储过程如下:


Actually you have to keep value as NULL and check in your front end if the value is NULL don''t show anything.
If for some reason you don''t want to allow NULL in the column, it will save 01-01-1900 and then you check in your front-end if the value is 01-01-1900, don''t show value.

Alternatively, in your stored procedure you can set like

select column1, column2, 
case when convert(varchar(10),yourDatecolumn,101) = '01-01-1900'
                then '-' 
                else yourDateColumn end)          as modifiedDate
from yourtable





我现在没有SQL访问权限,因此请在使用之前更正sytax。 />
Hoep有帮助。如果是,请将其标记为答案/ upvote。



Milind



I don;t have SQL access now, so correct the sytax before using.
Hoep that helps. If it does, mark it as answer/upvote.

Milind


您能说明原因吗?



您可以使用以下方法:既不存储具体日期,也不保持字段值为NULL(列应该可以为空)。

在您的客户端代码上(Web前端)或应用程序)将值为null的字段显示为'' - ''
Can you specify the reason?

You can use following approach: store neither concrete date, or keep field value as NULL (column should be nullable).
On your client code (web frontend, or application) display fields that have value of null as ''-''


这篇关于我想只存储“ - ”在sql server 2008中的datetime列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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