Replace first occurrence of substring in a string in SQL

后端 未结 4 870
粉色の甜心
粉色の甜心 2020-11-30 13:25

I have to fetch data from a @temp table which has something like \"or ccc or bbb or aaa\" I want to replace the first occurrence into space to get something like this \" ccc

4条回答
  •  猫巷女王i
    2020-11-30 14:06

    it seems you miss 2% preceding and trailing to the target string

    please try:

    select STUFF(@stringhere, PATINDEX('%' + @stringtofind + '%', @stringhere), LEN(@stringtofind), ' ')
    

提交回复
热议问题