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

SQL删除/替换字符串的一部分,sql,Sql,你好,我有个问题 我有以下格式的字符串格式的列数据: xxxxxxxx <***********> 这个命令不起作用,我知道这是因为REPLACE函数中的第二个参数。第二个参数应该是什么 如果有必要的话,我正在使用SQL Server 2008 谢谢你的帮助。试试这个 declare @s as varchar(50) set @s = 'axxxxxxxx <*****>' select substring(@s, 1, charindex('<', @s) -

你好,我有个问题

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

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

如果有必要的话,我正在使用SQL Server 2008

谢谢你的帮助。

试试这个

declare @s as varchar(50)
set @s = 'axxxxxxxx <*****>'
select substring(@s, 1, charindex('<', @s) - 1)
选择替换('abcdefghicde'、'cde'、'xxx')

将返回abxxxfghixxx

论据:

替换(字符串表达式、字符串模式、字符串替换)

字符串表达式

Is the string expression to be searched. string_expression can be of a character or binary data type.
字符串模式

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

Is the replacement string. string_replacement can be of a character or binary data type.

你看到这个链接了吗?谢谢你的快速回复。让它工作起来。我必须通过
select substring(@s,1,charindex('s)来解决这个问题
Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string ('').
Is the replacement string. string_replacement can be of a character or binary data type.