Understanding Column alias

There are two methods of creating alias name for a column

SELECT 100 as number
SELECT 100 number

Both result to 100 with column name number

You can use the keyword AS followed by alias name or use a space (But I prefer AS for better clarity and avoid mismatch in the result. See Missing comma and column alias for more information)

Did you know that in SQL Server the following will work same way as above?

SELECT 100number
SELECT 100.number
SELECT 100'number'
SELECT 100"number"
SELECT 100[number]

For string value, except dot followed by alias, all other will work

SELECT 'SQL Server'name
SELECT 'SQL Server' 'name'
SELECT 'SQL Server'"name"
SELECT 'SQL Server'[name]

It should be noted that without space or AS keyword, SQL Server implicitly making succeeding alphabets/alphanumrics as column alias

So you should be aware of this especially the first example


4 thoughts on “Understanding Column alias

  1. Parthipan and Prabakaran, What example do you want? You can execute the above SELECT statements and see how you get the column alias name although the expressions are different

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s