开发者

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

开发者 https://www.devze.com 2023-02-24 05:48 出处:网络
I\'m trying to write a column name using \".\" with no success sample: 开发者_如何学GoSELECT PrmTable.Value = MAX(Value)

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

sample:

开发者_如何学GoSELECT PrmTable.Value = MAX(Value)
FROM TempTable

or

SELECT MAX(Value) AS PrmTable.Value
FROM TempTable

Any idea ?


Just enclose it in square brackets, and it will work

e.g.

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


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]


SELECT [PrmTable.Value] = MAX(Value)

FROM TempTable

or

SELECT MAX(Value) AS [PrmTable.Value]
0

精彩评论

暂无评论...
验证码 换一张
取 消