SSIS Expressions are great
Previously I posted about how to obtain relative picture paths from your database, flip the direction of the “slashes” and delete the image using a ‘Filesystem Task.’ I posted a stored procedure that does a ‘replace’ on forward slashes with backslashes, and I don’t think that is the best way to do it. The database should have the least amount of work to do period. Expressions are a way to evaluate and calculate certain values on the fly. That being said, use expressions.
Example Scenario: You have a stored proc that returns a result set of relative paths (i.e. /images/yourface.jpg”). You want to turn that path into the full UNC path.
Step 1: Create a variable to store the returned path
- In the variables pane click Add Variable (call it ReturnedPath) as a String
- Create an other variable called BaseDir as a String and hard code the value for your base directory (i.e. \\fileserver\uploads)
- Create an other variable called FullPath as a String
Step 2: Create an expression for the FullPath variable
- Click on the variable FullPath and select EvaluateAsExpression to True
- Click and expand the Expression Property
- Expression should be: @[User::BaseDir] + REPLACE( @[User::ReturnedPath] ,”/”, “\\” )
What this does: It takes the hard coded value of BaseDir and concatenates the ReturnedPath with the forward slashes replaced with backslashes
Leave a Reply