blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

SSIS Junkie

SSIS: Using variables to store expressions

I have extolled the virtues of the expression language in SSIS more times than I care to remember and quite frankly regular readers of this blog must be fed up of me banging on about them. Well I make no excuse for it - property expressions dramatically increase the power of your SSIS packages - turning them into dynamic behemoths rather than little static workflows.

What I always thought would be nice though would be to have the ability to view the results of the expressions at debug time in the VS watch window. Well, whilst writing my previous blog post on Splitting a file into multiple files I devised a new strategy towards using expressions that I thought was worth sharing. Its incredibly simple as well.

Instead of putting expressions on object properties, put the expression into the 'Expression' property of a variable and set the object property expression to be the value of the variable instead. There are 3 benefits to doing this:

1) You can view the value of the expression in the watch window

2) You can leverage the OnVariableValueChanged event

3) Expressions can be shared by different object properties.

There you go. Three good reasons to put your expressions in variables rather than straight into a property expression.

 

Here's a screenshot from my aforementioned data splitting demo that shows the usefulness of being able to watch variable values in the watch window:

20051205scr.JPG

-Jamie

P.S. Thanks to Nick Barclay for his comment here: http://blogs.conchango.com/jamiethomson/archive/2005/12/04/2458.aspx#2459 that prompted me to write this post!

UPDATE: Another advantage of this approach is that you can raise OnInformation events containing the dynamic SQL. This means that the SQL statement will get logged by whatever log provider you are using.

Published 05 December 2005 09:20 by jamie.thomson

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Kirk said:

Jamie,
Excellent. You are truly showing off the combinatorial power of expressions. This is a great way to use variables, although not recommended for everything since it could get a bit confusing.
There are some really interesting things you can do with variables that reference other variables as well.
Hint, hint...
December 5, 2005 21:34
 

Professional Association for SQL Server (PASS) SIG said:

December 7, 2005 17:19
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
January 5, 2006 21:58
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
January 7, 2006 19:45
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
January 7, 2006 20:01
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
January 9, 2006 13:43
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
January 23, 2006 18:44
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
February 17, 2006 23:46
 

Jamie Thomson - Life, the universe and SSIS! said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices....
February 21, 2006 22:18
 

SSIS Junkie said:

I thought it would be worth publishing a list of guidelines that I see as SSIS development best practices.

November 8, 2006 21:52
 

SSIS Junkie said:

Someone recently left a comment on my blog about Package Template Locations asking if I could share my

March 12, 2007 09:45
 

Another SSIS User said:

Great Recommendation!! I build a dynamic SQL Constraint and it has worked in the past. Suddenly one of them is hung up and will read the design-time value of the variable instead of dynamic. I couldn't find a way to debug the property value it was

filling. Recompile etc. forcing cache remove didn't work.

??.[SQLCommand] = ".... > " + (DT_WSTR,12)@[User::VarName]

In the above it is always putting Zero for @User::VarName even though Debugger said, it had a value. Not sure where it is caching the value from and reading. I Changed as suggested in this blog to

??.[SQLCommand] = @User::MySQLCommand

Then

@User::MySQLCommand = ".... > " + (DT_WSTR,12)@[User::VarName]

Works Great and I can debug too!!! Thanks a bunch for this tip.

April 10, 2007 18:26
 

SSIS Junkie said:

A colleague recently pointed out this thread to me from Oren Eini's blog . The post is entitled SSIS'

July 27, 2007 07:33
 

Joe Horton said:

I have a BI solution with many packages.  I have a master_load all package

that calls the child packages in the order I wish.  In order to get "watch"

and "locals" information - it appears I have to debug the whole solution.

Isn't there a way to Execute Task or individual packages and get the

debugging features?  Or do I have to repoint my startup package each time to

the current package I'm working on?

May 13, 2008 18:29
 

jamie.thomson said:

Joe,

You can execute wichever package you want. Just right-click on it in Solution Explorer and hit 'Execute'.

Have I misunderstood the problem?

-jamie

May 13, 2008 20:40
 

skhan said:

What's the "round robin" about. Just curious.

August 15, 2008 20:02
 

jamie.thomson said:

skhan,

What are you referring to?

-Jamie

August 18, 2008 13:05
 

Favaz said:

Import the General Settings and u will get the Watch window while the Debug Break Point is on but not in menu, God knows where it comes from but it works

look here for more info,

http://forums.msdn.microsoft.com/en-US/vsdebug/thread/cd706330-2d04-4ff7-a38a-955afdef49cb/

August 23, 2008 15:09
 

Sponk said:

Are you honestly telling us that we must put the value of the variable into the expression of it rather then the actual value, if we want to view its "value" during runtime ? What the heck ? The more i read about ssis the more i'm thinking what a pos this is is...

October 27, 2008 08:08
 

jamie.thomson said:

Sponk,

I'll ignore your pointless last comment and answer your first question.

If you want to view the value of a variable at runtime then you can use the watch window. This allows you to see what the variable's "Value" proeprty is set to.

That "Value" property can be set explicitly OR it can be the result of an expression.

Hence I think the answer to your question is no, you don't have to put the value into a variable in order to view it.

Hope that helps.

-Jamie

October 27, 2008 09:09

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems