.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Customizing the Display

Posted By:Ravi Ranjan Kumar       Posted Date: July 01, 2011    Points: 200    Category: DataBase    URL: http://www.dotnetspark.com  

This article enable you to Customize Column Value using SQL Query in SQL Server

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..  :)

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend