How can I remove leading and trailing quotes in SQL Server?

前端 未结 14 1440
青春惊慌失措
青春惊慌失措 2020-12-15 03:28

I have a table in a SQL Server database with an NTEXT column. This column may contain data that is enclosed with double quotes. When I query for this column, I want to remo

14条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 03:57

    I have just tested this code in MS SQL 2008 and validated it.

    Remove left-most quote:

    UPDATE MyTable
    SET FieldName = SUBSTRING(FieldName, 2, LEN(FieldName))
    WHERE LEFT(FieldName, 1) = '"'
    

    Remove right-most quote: (Revised to avoid error from implicit type conversion to int)

    UPDATE MyTable
    SET FieldName = SUBSTRING(FieldName, 1, LEN(FieldName)-1)
    WHERE RIGHT(FieldName, 1) = '"'
    

提交回复
热议问题