Add Custom Columns to Target/Data Warehouse Tables
How to add a custom column / field to the target table loaded into the data warehouse.
Preparation
Decide on the name and data type of the custom column/field you want to add to the target table.
Design the formula/calculation for the value of the custom column. Code the formula as a T-SQL expression.
Add the Custom Column with the AS
Keyword
Add the custom column to the SELECT clause in the Extract SQL Statement panel.
Use the AS syntax. For example1 as [my_count]
Open the Design page .
On the Design page select the row for the custom column.
Modify the Dw Data Type as required
Enter the T-SQL expression into T-SQL Expression.
Confirm.
Make note of the load option selected in the Load panel.
Select Load All in the Load panel.
Select Load Now .Restore the load setting as required – see step #4.
NOTES
The SQL used in the Extract SQL Statement must be compatible with the Source Object.
For more on this see ETL+ Extract SQL Statement Panel. ETL+ Extract SQL Statement Panel | SourceDrivers has links for the right SQL Syntax to Use with Various Source Drivers and Source Systems.
Using the AS
keyword in the SELECT
statement
The AS
keyword adds a column to the result-set of the SELECT query. The syntax does not allow you to assign a specific data type to the column.
The data type of the new column is determined by SQL based on the the value or expression in the AS
expression.
SQL Expressions by ETL+ Source Driver / Source System | |||
---|---|---|---|
Source Data Type 1️⃣ | MS SQL Server /T-SQL | Text (.CSV) | ANSI Standard SQL |
datetime |
|
| |
decimal(28,6) |
|
1️⃣ The data type shown in the Source Data Type column on the ETL+ Design Page.
ETL+ Extract SQL Statement Panel | SourceDrivers has links for the right SQL Syntax to Use with Various Source Drivers and Source Systems.
AS
SYNTAX
<constant> AS <new-column-name>
<constant>
== a number (e.g.; 22, 99.1) or string ("brown fox")
<expression> AS <new-column-name>
<expression>
== date, datetime, string or numeric SQL function<expression>
== A constant, function, any combination of column names, constants, and functions connected by an operator or operators, or a subquery.
Miscellaneous
Tricks and Workarounds
CAST(<existing-column> AS DATETIME) AS new_hire_date
Related Pages
ETL+ Extract SQL Statement: CONVERT() – T-SQL’s
CONVERT
function vs. ANSI standard SQLCAST
function. is platform agnostic.