更新列的子串 [英] Update substring of a column

查看:189
本文介绍了更新列的子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2008数据库中有一个表,名为 Meter 。此表有一个名为 Name 的列。

I have a table within a SQL Server 2008 database called Meter. This table has a column called Name.

Name 中的每个条目都有以下的前缀 ZAA\ 。我想将此前缀更改为 ZAA _ ,而不会影响列中的其余文本。

Each entry within the column Name has a prefix of the following ZAA\. I'd like to change this prefix to ZAA_ without affecting the rest of the text within the column.

推荐答案

UPDATE Meter
SET Name = 'ZAA_' + SUBSTRING(Name, 4, LEN(Name))
WHERE SUBSTRING(Name, 1, 4) = 'ZAA\'

编辑:

或以@Damien_The_Unbliever声明,使用索引:

Or as @Damien_The_Unbliever states, to use an index:

UPDATE Meter
SET Name = 'ZAA_' + SUBSTRING(Name, 4, LEN(Name))
WHERE Name LIKE 'ZAA\%'

EDIT

在您的评论中,尝试使用此语句修复额外的 \

From your comment, try this statement to fix the additional \:

UPDATE Meter
SET Name = 'ZAA_' + SUBSTRING(Name, 5, LEN(Name))
WHERE Name LIKE 'ZAA_\%'

这篇关于更新列的子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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