Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > S > SELECT

AS

Scroll Prev Top Next More

This clause dynamically renames columns in a SELECT clause.

 

Selectas

 

Options

 

,

Indicates that this part of the command is repeatable.

 

colname

Specifies a column name. The column name is limited to 128 characters.

 

(expression)

Determines a value using a text or arithmetic formula. The expression can include other columns from the table, constant values, functions, or system variables such as #date, #time, and #pi.

 

AS alias

Determines the alias of the column. This may be used to refer to the column in other locations.

 

FROM tableview

Specifies the table or view to draw information from.

 

About the SELECT AS command

 

The SELECT AS command functions exactly like any other SELECT command and will accept all other SELECT options. The one noticeable exception is that this allows you to give a column an alias. This can be most useful when used in conjunction with the CREATE VIEW command.

 

Examples

 

The following 3 examples are based on the ConComp database.

 

The following command selects the EmpID and the EmpName columns from the Employee table and renames them to "EmployeeID" and "Name".

 

SELECT EmpID AS EmployeeID,EmpName AS Name FROM Employee

 

The following command creates a VIEW using the SELECT AS notation. This view contains a column for Employee ID, Employee Name (which is a single column based on the EmpFName and EmpLName columns) from the Employee table and the Transdate and NetAmount columns from the Transmaster table. The immediately following command browses the Employee Name, Transdate and Netamount column. For more on Views please see CREATE VIEW.

 

CREATE VIEW EmpAmount AS SELECT T1.EmpID, +

  (T1.EmpFName + ' ' + T1.EmpLName) AS EmpName, +

  T2.TransDate,T2.NetAmount FROM Employee T1, +

  TransMaster T2 WHERE T1.EmpID = T2.EmpID

 

BROWSE EmpName,TransDate,NetAmount FROM EmpAmount

 

This final example uses IDQuotes to create a column name with spaces in it and then uses the SELECT HTML option to turn that into an HTML table with the column name. The OUTPUT commands redirect output to a file called "Emp.HTM" and then back to the screen. We do NOT recommend using this method to create VIEWS or TABLES with names that contain spaces as this could lead to Database Corruption.

 

OUTPUT EMP.HTM

SELECT EmpID as `Employee ID` FROM Employee HTML

OUTPUT SCREEN