As per my knowledge I am using in three ways of giving alias names to the database table column in SQL Server while selecting,
Below are the types which I am using:
1. Giving the alias name in Square Bracket [ ]
2. Giving the alias name with Underscore _
3. Giving the alias name with Double Quotes “ ”
4. Giving Direct Expected Name
1. Square Brackets
The required column/ header name should be with in the Square Brackets only, with in this bracket we can give spaces also in expected name, so mostly we will use these kinds of brackets when we have space in our expected column name, below is the example.
Example:
SELECT
Empno --Original Name of
the column
, Empno AS [Employee Number]--Alias Name of
the Column FROM tbl_Emp
O/P
2. Underscore _
The required column/ header name should be with Underscore i.e. _, with this underscore only between the two words like Employee and Name, we have to concatenate these two with Underscore I.e. Employee_Name
Example:
SELECT
Empno --Original Name of the column
, Empno AS Employee_Number --Alias Name of the Column FROM tbl_Em
O/P
3. Double Quotes:
The required column/ header name should be within the Double Quotes only, with in this double quote we can give spaces also in expected column name, so this also mostly we will use these kinds of Quotes when we have spaces in our expected column name, below is the example.
Example:
SELECT
Empno --Original Name of the
column
, Empno AS "Employee
Number"--Alias Name of the Column FROM tbl_Emp
O/P
4. Direct Expected Name:
This like directly whatever you what you can give, there is no such condition like above, but here we can’t write column name with spaces, it will work only for single world column name
Example:
SELECT
Empno --Original Name of the column
, Empno AS "EmployeeNumber"--Alias Name of
the Column
FROM tbl_Emp O/P
Please comment below