SQL Server Column Headings

SQL Server - SELECT Statement with column headings

SQL Server provides the SELECT statement to access and retrieve data from a database.

SELECT statement prompts the SQL Server to query a single table or multiple tables in the database.

SELECT query results are displayed with the column names as the column names specified in the table at the time of its creation.

Column headings also need to be assigned to the computed columns in the SELECT statement.

SELECT Statement with user-defined column headings

Two different methods are available in SQL Server to provide user-defined column headings.

SELECT statement to retrieve the specific columns with user-defined columns heading from a single table.

Method 1

SELECT column_heading1 = column_name1 [, column_heading2 = column_name2, ...]
FROM table_name 

Method 2

SELECT column_name1 column_heading1 [, column_name2 column_heading2, ...]
FROM table_name 

here column_heading is the user-defined column heading and column_name is the name of the column in the database table.

SELECT Column Headings Example

Method 1

SELECT 'Employee ID'=Id, 'Employee Name'=Name, 'Department Id'=DeptId, 'Employee Email'=Email
FROM Employee
Output:
Select statement with column headings output

Method 2

SELECT Id 'Employee ID', Name 'Employee Name', DeptId 'Department Id', Email 'Employee Email'
FROM Employee
Output:
Select statement with column headings output

Invalid Query Column Headings

Method 1

SELECT Id 'Employee ID', Name 'Employee Name', DeptId='Department Id', Email 'Employee Email'
FROM Employee
Output:
Select statement with column headings output

Method 2

SELECT Id 'Employee ID', Name 'Employee Name', 'Department Id' DeptId , Email 'Employee Email'
FROM Employee
Output:
Select statement with column headings output



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^