In SQL 2017 TRIM
was introduced.
Your code would look like this:
SELECT TRIM( '"'' ' FROM '"SQL Server String Function"') AS Result
Note: I don't have access to SQL 2017 to give you a working sample.
For earlier versions it is a little more complicated (credit goes to Randi Vertongen):
DECLARE @pat VARCHAR( 10 )= '%[^''" ]%'
DECLARE @strTbl TABLE( string VARCHAR( 40 ))
INSERT INTO @strTbl VALUES
( '''" SQL Server "String Function "''' ),
( '''" SQL Server "String Function' ),
( 'SQL Server "String Function' ),
( 'SQL Server "String Functio''n' );
SELECT RIGHT( string, LEN( string ) - PATINDEX( @pat, string ) + 1 ) -- Remove leading
FROM
( SELECT LEFT( string, LEN( string ) - PATINDEX( @pat, REVERSE( string )) + 1 ) AS string -- Remove trailing
FROM @strTbl ) AS a;
How it works:
'%[^''" ]%'
- is looking for the first non-excluded character in string
PATINDEX( @pat, REVERSE( string ))
- finds the last non-excluded character
Limitations
Due to LEN
function not counting trailing spaces, this logic will work correctly if you want to keep trailing spaces.