Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to write a column name using "." with no success

sample:

SELECT PrmTable.Value = MAX(Value)
FROM TempTable

or

SELECT MAX(Value) AS PrmTable.Value
FROM TempTable

Any idea ?

like image 397
Liran Ben Yehuda Avatar asked Apr 12 '11 11:04

Liran Ben Yehuda


2 Answers

Just enclose it in square brackets, and it will work

e.g.

SELECT MAX(Value) AS [PrmTable.Value]
FROM TempTable
like image 112
AdaTheDev Avatar answered Oct 16 '22 20:10

AdaTheDev


I would not recommend you use field names which always require you to enclose the name in brackets, it becomes a pain.

Also the period is used in SQL Server to denote schema and database name separators. Using your field name the full name for a field becomes:

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

That just looks odd and would probably confuse other DBAs. Use an underscore to separate words in your field names, it's a much more common style:

[DatabaseName].[SchemaName].[TableName].[FieldName_WithUnderscore]
like image 41
Tony Avatar answered Oct 16 '22 20:10

Tony