Replace whole word using ms sql server “replace”

后端 未结 3 1176
借酒劲吻你
借酒劲吻你 2021-01-19 04:28
declare @str varchar(50)=\'GoodLuck Markand\'
declare @replacedString varchar(50)
set @replacedString = replace(@str,\'Good\',\'Better\')
print @replacedString
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-19 04:54

    This does not seems to be functionality of Replace, as per MSDN; You have to use give spaces at both side of the word being searched and replaced.

    replace(@str,' Good ',' Better ')
    

    Replaces all occurrences of a specified string value with another string value.

    Refer MSDN

    Syntax

    REPLACE ( string_expression , string_pattern , string_replacement )
    

    Arguments

    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 (''), and must not exceed the maximum number of bytes that fits on a page.

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

提交回复
热议问题