Using SQL Server 2019 Standard. You can use QUOTENAME without passing the character parameter, but it will use brackets. 99% of the time I want to use an apostrophe. Is there a way to change the default character without having to pass it every time?
Thank you.
CodePudding user response:
I feel like the chicken who can't cross the street without his motives being questioned. Thank you Mr. Smith. That was the answer.
I question that too. Whilst single quoted identifiers can be used in some limited situations you shouldn't use them. What use case requires this? The answer is "no" anyway – Martin Smith
CodePudding user response:
If by "apostrophe", you mean a character that looks like this (`), then the answer is "No, not directly".
If by "apostrophe", you really mean a single quote that looks like this ('), then the answer is "YES".
SELECT QUOTENAME(SomeStringExpression,'''')
If you really do mean an "apostrophe" that looks like this (`), the REPLACE can help assuming that you don't have double quotes embedded in the SomeStringExpression.
SELECT REPLACE(QUOTENAME(SomeStringExpression,'"'),'"','`')