Upload
jasonyousef
View
457
Download
0
Tags:
Embed Size (px)
Citation preview
LET’S TALK DYNAMIC….SSIS EXPRESSIONS AND VARIABLES
Jason Yousef, MS MCITP MCTS
Why would you listen to me!• Sr. Database Engineer.• SQL BI & SQL Developer Trainer.• Started with SQL Server 7.
Agenda Overview (Variables / Expressions). Variables – Data Types, scope, Namespace and naming conventions. Variables – Debugging using Breakpoints. Variables – User & System Variables using ‘Package Configurations’. Variables – Using .NET in a Script Task. (Control Flow) Variables – Using .NET in a Script Component. (Data Flow) Expressions and Dynamic SSIS. Expressions - Operators, Functions, Literals and Casting. Using the Expressions builder and the Expression Tester Application. Common String, Numeric, NULL, Conditional and Date & Time
examples. Q & A.
Overview Variables:
A place holder for your values, used to store and pass values between tasks and containers internally or between packages (child and parent packages).
Expressions: An expression is a combination of multiple
operators and functions and could reference multiple columns or variables to yield a single data value.
Variables
Right click (Designer) VariablesSSIS (Menu) VariablesView (Menu) OTHER WINDOWS Variables
Variables – Date Types
Data types are .Net data typesSSIS supports the following data types:
http://tinyurl.com/ssisDT
Boolean Byte Char
DateTime DBNull Double / Decimal
Int16 Int32 Object
SByte String UInt32
UInt64 Int64 Single
Variables – Scope , NameSpace
A way to organize your package and limit your variables to a certain task using Scopes or NameSpaces.
As variables’ names are unique, you can have the same name across multiple ‘Scopes’ or ‘Name spaces’
Variables – Naming Conventions
Name: Name of your variable. Preferable and suggested to use a meaningful Camel Case name, including its data type abbreviation, such as:
StrFName: For a string data type variable. IntTotalSales: For an integer data type variable, you
can also specify if it’s Int16, Int32 or Int64. (too much!) DTSalesDate: For a Date Time variable. BoolFileFound: For a Boolean variable, holds a flag (0
or1).
Variables – Breakpoints Debugging values.
Variables – Package Configurations
Read & write to system and User variables using ‘Package Configurations’
Variables – Reading / Writing Using .Net
Script Task (Control Flow)
Variables – Reading / Writing Using .Net
Script Component (Data Flow Task)
Variables using .NET
Demo
Expressions - Overview used to assign values to variables, update or populate
properties at run time, define constraints in precedence constraints, and provide the expressions used by the For Loop container.
The language is somehow similar to the curly braces languages (C++,C# or Java ).
Almost any task in SSIS, if not all, can use expressions to make its properties dynamic.
“Execute SQL Task” dynamic SQL query. “Derived Column” validate or assign value to a column. “Conditional Split” to split a column based on a specific condition. “Precedence Constraints“ direct the flow to a different route based on
a custom condition within the Control Flow.
Expression Builder SSIS 2005, 2008
SSIS 2012 Expression Task
Expression Editor & Tester Tool
http://expressioneditor.codeplex.com/
Expressions - Literals
Hard coded info that you provide when building expressions (Numeric, String and Boolean) to give more info about the expression’s value.
Numeric
Numeric literals checked for decimal points before getting casted to DT_UI4, and to DT_NUMERIC if there’s a decimal. To override use one of these suffixes.
Expressions - Literals
Boolean (True OR False) String
Escape Description
\n New Line
\b Backspace
\” Creates a Double Quotes
\t Tab
\\ Creates a backslash, used for URLs
Expressions - Operators
+ Add or (Concatenate)
- Subtracts or (Negates )
* Multiply / Divide
|| Logical OR && Logical AND
== Equal != Un Equal
? : Conditional < Less Than
> Greater Than <= Less Than or Equal
>= Greater Than or Equal
& Bitwise AND
Expressions - Casting Converts an expression from one data
type to a different data type. Implicit - Automatically Explicit – Using CAST
DT_BOOL True / False
DT_DBDATE Date
DT_DBTIMESTAMP
Date & Time
DT_I4 Four-byte, signed integer.
DT_DECIMALDT_NUMERIC
Decimal with precision and scale
DT_WSTR Unicode character string
Demo
Most commonly used expressions
Demo
SSIS 2012 New Expressions
Questions & Contact Info Email: [email protected] Blog: www.jasonyousef.com Twitter: @Huslayer
Speaker Rating : http://spkr8.com/t/18591
Thanks for coming!