Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE #temp > ( > fieldname varchar(10) > ); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO #temp > ( > fieldname > ) > VALUES > ('"bla"'), > ('"bla'), > ('bla"'), > ('bla'), > ('bla '), > ('bla "'); > > <pre> 6 rows affected > </pre> <!-- --> > SELECT CASE WHEN RIGHT(fieldname,1) = '"' AND LEFT(fieldname,1) = '"' THEN REVERSE(STUFF(REVERSE(STUFF(fieldname, 1, 1, '')), 1, 1, '')) > WHEN RIGHT(fieldname,1) = '"' THEN REVERSE(STUFF(REVERSE(fieldname), 1, 1, '')) > WHEN LEFT(fieldname,1) = '"' THEN STUFF(fieldname, 1, 1, '') > ELSE fieldname END as fieldname > FROM #temp > > <pre> > | fieldname | > | :-------- | > | bla | > | bla | > | bla | > | bla | > | bla | > | bla | > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=cc2e3fa8f0742584e051589bcd142f17)*
back to fiddle