How to replace first and last character of column in sql server?

后端 未结 9 2783
名媛妹妹
名媛妹妹 2021-02-19 11:43

I have a database column and its give a string like ,Recovery, Pump Exchange,.

I want remove first and last comma from string.

Expected Result :

9条回答
  •  清酒与你
    2021-02-19 11:57

    Using LEN could backfire because LEN ignores trailing spaces. These could be added because of ANSI_PADDING defaulting to ON. So, you'd need RTRIM.

    For completeness, I've added LTRIM too...

    REVERSE(SUBSTRING(REVERSE(RTRIM(LTRIM(SUBSTRING(MyCol, 2, 8000)))), 2, 8000))
    

提交回复
热议问题