How do you strip a character out of a column in SQL Server?

前端 未结 4 706
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 06:49

How do you remove a value out of a string in SQL Server?

4条回答
  •  臣服心动
    2020-12-05 06:51

    Take a look at the following function - REPLACE():

    select replace(DataColumn, StringToReplace, NewStringValue)
    
    //example to replace the s in test with the number 1
    select replace('test', 's', '1')
    //yields te1t
    

    http://msdn.microsoft.com/en-us/library/ms186862.aspx

    EDIT
    If you want to remove a string, simple use the replace function with an empty string as the third parameter like:

    select replace(DataColumn, 'StringToRemove', '')
    

提交回复
热议问题