T-SQL: The ‘quote_character’ in the Built-in Function QUOTENAME()


I needed to quote an identifier (a column name) with “<“. I checked the documentation for the build-in function QUOTENAME() and I did not find the information that I need. Here is a quick T-SQL to show which characters we can use as a second argument of the function.

DECLARE @Counter SMALLINT = 1;

WHILE (@Counter <= 255)
BEGIN
	IF (QUOTENAME(@Counter, CHAR(@Counter)) IS NOT NULL)
	BEGIN
		PRINT CONCAT(@Counter, ' --> >', CHAR(@Counter), '< --> ', QUOTENAME(@Counter, CHAR(@Counter)))
	END
	SELECT @Counter += 1;
END

Keep it simple :-)

Leave a comment

Your email address will not be published. Required fields are marked *