Changing Result Sets

So far, every column you have requested has been retrieved and displayed as the data was stored. However, there will be many times when you will need to change the way the data is displayed. This next section will discuss the different ways that you can change the labels of the displayed columns or modify the data in the columns by using operators and functions.

Using Column Aliases

You will find that the names of the columns as defined in the database are not exactly easy to read as shown in the following example:

use pubs
select emp_id, job_id, job_lvl, pub_id
from employee

Results:

 emp_id job_id job_lvl pub_id --------- ------ ------- ------ PMA42628M 13 35 0877 PSA89086M 14 89 1389 VPA30890F 6 140 0877 H-B39728F 12 35 ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.