Replace whole word using ms sql server “replace”

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


        
3条回答
  •  天命终不由人
    2021-01-19 04:45

    Append empty space at start and end of the string then replace ' Good ' with ' Better '. Finally use Ltrim and Rtrim to remove the empty space at start and end of the string

    DECLARE @str VARCHAR(50)='Good Luck Good MarkandGood Good'
    DECLARE @replacedString VARCHAR(50)
    
    SELECT rtrim(ltrim(Replace(replace(' '+@str+' ',' Good ',' Better '),
    ' Good ',' Better ')))
    

提交回复
热议问题