替换/用 - [英] Replace a / with a -

查看:102
本文介绍了替换/用 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想运行查询来替换日期字段中的值。

目前它是2013/12/02 01:12:49:856并在数据库中存储为varchar

我想用/替换所有记录上的/

我试过以下脚本

Hi

I want to run a query to replace the values in my date fields.
Currently it is as 2013/12/02 01:12:49:856 and is stored as varchar in the database
I want to replacce the / with a - on all the records
I have tried the following script

UPDATE AuditResults
SET lastupdated = REPLACE(lastupdated, N'/', N'-')






and

UPDATE AuditResults
SET lastupdated = REPLACE(lastupdated, '/', '-')



但这不起作用。

其他任何其他sugges tions?



提前谢谢你


But this does not work.
Any other suggestions?

Thank you in advance

推荐答案

你可以转换和更新记录,


You can convert and update the records,

SELECT CONVERT(VARCHAR(23), GETDATE(), 121)







UPDATE AuditResults
SET lastupdated =CONVERT(VARCHAR(23), lastupdated , 121)









参考:


phil.o是对的 - 将日期时间值存储为字符串是一个非常愚蠢的决定,应该更改(并决定它的人重击用坚固的东西绕过头部。



但是......我刚检查过这两个版本工作正常,所以我怀疑你的代码而不是其他任何东西。您是否添加了一个您没有告诉我们的WHERE子句?
phil.o is right - storing datetime values as string is a spectacularly stupid decision, and should be changed (and the person who decided on it thumped round the head with something solid).

But...I just checked here and both versions worked fine, so I suspect your code rather than anything else. Did you add a WHERE clause that you didn't tell us about?


这篇关于替换/用 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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