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

前端 未结 14 1410
青春惊慌失措
青春惊慌失措 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 04:16

    The following script removes quotation marks only from around the column value if table is called [Messages] and the column is called [Description].

    -- If the content is in the form of "anything" (LIKE '"%"')
    -- Then take the whole text without the first and last characters 
    -- (from the 2nd character and the LEN([Description]) - 2th character)
    
    UPDATE [Messages]
    SET [Description] = SUBSTRING([Description], 2, LEN([Description]) - 2)
    WHERE [Description] LIKE '"%"'
    

提交回复
热议问题