从 varchar 字段中删除单个字符 SQL Server 2008 [英] Remove a single character from a varchar field SQL Server 2008

查看:48
本文介绍了从 varchar 字段中删除单个字符 SQL Server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个 varchar 列的表,这些列与我在另一个表中的主键几乎相同,但句点 (.) 除外.我查看了 T-SQL 中的 replace 函数,但第一个参数不是表达式.如何使用 SQL 删除所有出现的特定字符?似乎正确的答案可能是用零长度字符串替换.这么近吗?

I have a table with several varchar columns that are almost identical to primary keys I have in another table, with the exception of a period (.). I've looked at the replace function in T-SQL but the first argument isn't an expression. How can I remove all occurrences of a particular character with SQL? It seems like the correct answer might be to replace with a zero length string. Is that close?

对于认为这个问题没有表现出研究努力的人来说,这主要是由于对文档本身的误解.

To whomever felt the question didn't exhibit research effort it was mainly due to a misunderstanding of the documentation itself.

推荐答案

您可以在列值上使用 REPLACE 直接更新表:

You can update the table directly using REPLACE on the column values:

UPDATE myTable
SET myColumn = REPLACE(myColumn, '.', '')

这篇关于从 varchar 字段中删除单个字符 SQL Server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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