Sometimes, we might be required to change the way the data is displayed. for example, if the names of columns are not descriptive. we might need to change the column headings by creating user-defined headings.
Consider the following example that display EmployeeID,MaritalStatus,Gender and LoginID from the HumanResources.Employee table of the AdventureWorks database. the report should contains column heading different format :
We can write the query in the following ways:
Way 1 :- select 'Custom CoulmnName'= real_Column_Name,.. from tablename
Way 2 :- select real_column_name 'Custom Column Name',... from tablename
Way 3 :- select real_column_name as 'custom column name',.. from tablename
the SQL server will display the same output for query when using given way syntax as show in the following figures :-
Using Way 1
Using Way2 or Way3
Similarly, we might be required to make results more explanatory. in such case, you can add more text to the values displayed by the column name by using literals.
Literals are string value that are enclosed in single quotes and added to the SELECT statement.
The literal value is printed in a separate column as they are written in the Select list.
therefore, literals are used for display purpose
the Following SQL query retreives the EmployeeID and their loginid with the literak XY value
Take a look how
So Keep Enjoying with customizing Column Values.. :)