How to write a column name with a dot (".") In a SELECT clause?

I am trying to write a column name using ".". without success

Example:

SELECT PrmTable.Value = MAX(Value) FROM TempTable 

or

 SELECT MAX(Value) AS PrmTable.Value FROM TempTable 

Any idea?

+6
source share
3 answers

Just enclose it in square brackets and it will work

eg.

 SELECT MAX(Value) AS [PrmTable.Value] FROM TempTable 
+15
source

I would not recommend that you use field names that always require you to enclose the name in parentheses, this becomes a pain.

Also, a period is used in SQL Server to denote schema and database name separators. Using your field name, the full field name will look like this:

 [DatabaseName].[SchemaName].[TableName].[FieldName.WithPeriod] 

This looks weird and is probably confused by other database administrators. Use underscore to separate words in field names; this is a much more common style:

 [DatabaseName].[SchemaName].[TableName].[FieldName_WithUnderscore] 
+10
source
 SELECT [PrmTable.Value] = MAX(Value) FROM TempTable or SELECT MAX(Value) AS [PrmTable.Value] 
+3
source

Source: https://habr.com/ru/post/885720/


All Articles