我的表包含这样的值
Name
______
Name(122)
anotherName(12312)
Another2Name(12321)
Name(2)Name(123213)
我希望它们看起来像这样:
Name
______
Name
anotherName
Another2Name
Name(2)Name
如何创建查询或更新表以删除结尾的“(###)”。
对此有任何帮助就太好了
我尝试了几种方法,删除括号后的所有内容,但某些值的名称中包含括号。 我尝试的另一种方法是删除所有数值,但是您可以看到名称中包含数字的示例,例如 Another2Name。
这是获取某些内容的最后一个索引的方法:
select right([Name], charindex('(', reverse([Name]) + '_') - 1) from yourtable
这就是选择子字符串的方法:
SELECT SUBSTRING([Name], 1, right([Name], charindex('(', reverse([Name]) + '_') - 1)) AS ExtractString from yourtable;
这就是您更新它的方法:
update yourtable set [Name] = SUBSTRING([Name], 1, right([Name], charindex('(', reverse([Name]) + '_') - 1))
未经测试,如果我有错别字,请告诉我。