SQL删除/替换字符串的一部分

时间:2012-01-30 17:40:41

标签: sql

您好我有问题

我有以这种格式的字符串格式的列数据:

xxxxxxxx <***********>

我希望与xxxxxxx相关,但要摆脱<***********>,其中<***********>可以是任何长度的任何类型的字符串。

到目前为止,我有这个命令,但是我无法绕过其余部分。

update Claims
set ClaimInitiatedBy = REPLACE(ClaimInitiatedBy,LIKE '% <%>','')
where ClaimInitiatedBy LIKE '% <%>'

这个命令不起作用,我知道这是因为REPLACE函数中的第二个参数。第二个参数应该是什么工作?

我正在使用SQL Server 2008,如果这很重要的话。

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

declare @s as varchar(50)
set @s = 'axxxxxxxx <*****>'
select substring(@s, 1, charindex('<', @s) - 1)

<强>输出:

axxxxxxxx 

答案 1 :(得分:0)

试试这个

SELECT REPLACE(&#39; abcdefghicde&#39;,&#39; cde&#39;,&#39; xxx&#39;);

将返回abxxxfghixxx

参数:

REPLACE(string_expression,string_pattern,string_replacement)

string_expression

Is the string expression to be searched. string_expression can be of a character or binary data type.

string_pattern

Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string ('').

string_replacement

Is the replacement string. string_replacement can be of a character or binary data type.
相关问题