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 :-)


About Peter Lalovsky

I am Microsoft SQL Server certified professional, creating with T-SQL, SSRS, SSIS, ASP.NET/C#, Azure, Python, PowerShell and more on a daily basis since year 2006. In 2016 i wrote a book for beginner and intermediate T-SQL programmers which you can download here. This blog is something like my personal programming documentation. When i am not in front of a computer, i am around my paper car – Trabant 601.

Leave a comment

Your email address will not be published.