Quoth Chad Callihan, “Occasionally more”:
QUOTENAME can be used to make sure database objects are valid in your query. Most of the time, objects like table names only contain valid characters, so there’s nothing to worry about. But nobody’s perfect. Let’s look at an example of what can happen when somebody creates a table with a forward slash in the name and see how QUOTENAME can be used to query against it.
QUOTENAME
is also a good way of preventing SQL injection, though I still prefer appropriate use of exec sp_executesql
in any case in which it’s possible to use.