Reputation: 48066
I have a Location table in my OLTP which, while coding SSIS against it, I found a LocationCode column name to have a trailing space in it.
Create Table Location
(
[LocationId] INT IDENTITY (1, 1)
[LocationCode ] INT
)
Note that LocationCode column name has a trailing space.
And yet, the following code works.
SELECT LocationCode
From Location
As a matter of fact, we located several places where the trailing space is used in stored procs, and it has continued to work.
How is this possible?
Upvotes: 2
Views: 614
Reputation: 48066
In addition to what @Matt Rogish said, a trailing space in a column name is not treated like any other special character. It is actually ignored when parsing queries (whereas a hyphen or a tilda would not be ignored).
I have submitted a bug to Microsoft Connect for SQL Server.
Upvotes: 0
Reputation: 24883
If delimited identifiers are used when naming an object and the object name contains trailing spaces, SQL Server stores the name without the trailing spaces.
http://msdn.microsoft.com/en-us/library/ms176027%28SQL.90%29.aspx
p.s. Delimited identifiers everywhere is a code smell -- they should be used SPARINGLY, not for every identifier.
Upvotes: 5