Tuesday, 13 January 2015

How to Change Column Heading In SQL

Usually when you query data from a table, the result is displayed with column names as the headings. Sometimes such headings are truncated and become difficult to understand. You encountered one such instance in the previous example, where you added an arithmetic expression to your query and the corresponding heading appeared as: 12 * (SALARY + 1000). You can change this heading into a meaningful title by using column alias clause. An alias is just an alternate name for a column. Add a column alias immediately after the column name (or expression), with a space between them. If an alias contains spaces, special characters (/ or #), or is case sensitive; it should be enclosed in double quotation marks. The AS keyword can also be included to comply ASNI SQL standards. The second statement uses a space between the two words and is therefore enclosed in double quotations.

    SQL Statement 

SELECT        last_name, salary, 12 * (salary + 1000) AS  ANNUAL_SALARY
FROM          employees;

SELECT       last_name, salary, 12 * (salary + 1000) AS  “Annual Salary”
FROM          employees;


    Output 


No comments:

Post a Comment