Impact of Quotes in T-SQL for Column Name Is there a difference between the two T-SQL commands below ?


Column name with quotes 

SELECT SUM(DATALENGTH('ColumnName')) / 1048576.0 AS ColumnName 
FROM DatabaseName.Schema.Tablename

Column name without quotes

SELECT SUM(DATALENGTH(ColumnName)) / 1048576.0 AS ColumnName  
FROM DatabaseName.schema.Tablename
Yes, the first variant will give you the data length of the text 'ColumnName' whereas the second will most likely get you nearer the results you are looking for (which I assume is the total length of all data within the given column). 

In SQL Server if you are looking for quoted identifiers you can use the standard " or square brackets. You only need to quote names that are reserved keywords like TABLE, INDEX etc... but as a general code-style tip I recommend picking a quoting scheme and using it consistently within your code. It makes it easier for other developers to read and pick up your scripts.

SQL Server: SET QUOTED_IDENTIFIER