SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to form SSIS expression for derived column transformation?

The following expressions can be used in the Derived Column Transformation Editor expression cell.

A derived column is a new column which is build from other input column(s). The \ signifies the escape character within the double quotes.

-- SSIS expressions

-- SSIS derived column expression

-- SSIS replace

 

/* Replace "a" with "A" in ShipName column */

REPLACE(ShipName,"a","A")

REPLACE(ShipName,"\x0061","A")

REPLACE(ShipName,"\x0061","\x0041")

REPLACE(ShipName,"a","\x0041")

 

/* Replace CR with empty string - filter out CR */

 

REPLACE(ShipName,"\x000D","")

REPLACE(ShipName,"\r","")

 

/* Replace LF with empty string - filter out LF */

 

REPLACE(ShipName,"\x000A","")

REPLACE(ShipName,"\n","")

 

/* Replace tab with empty string - filter out tab */

 

REPLACE(ShipName,"\x0009","")

REPLACE(ShipName,"\t","")

 

/* IF...ELSE... equivalent */

SalesActual >= SalesPlan ? "Sales target met" : "Sales target missed"

-- If AccountNo column is less than 6 digits, business account, else consumer account

(DT_UI8)AccountNo < (DT_UI8)99999 ? "BUSINESS" : "CONSUMER"

/* Translate expression: either shipped or NULL */

(ShipmentCode == "C") ? "Shipped" : NULL(DT_WSTR, 8)

/* Elapsed days since CreateDate */

/* SSIS GETDATE() returns the current system date in DT_DBTIMESTAMP format */

/* SSIS DATEDIFF function is similar to T-SQL DATEDIFF */

DATEDIFF("dd", (DT_DATE) CreateDate,GETDATE())

------------

-- Strip time from datetime OrderDate column

-- SSIS substring

SUBSTRING((DT_WSTR,"25")(DT_DBDATE)OrderDate,1,10)

-- 2015-03-15

------------

/* Format current datetime to YYYY/MM/DD style */

(DT_WSTR,4)YEAR(GETDATE()) + "/" +

RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + "/" +

RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)

 

------------

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.