2

I've done quite a bit of searching on this but haven't been able to come up with a solid solution. I have a use case where for example I want to include the date in the file name, let's say I use the following formula:

"EmployeeCount_"+(DT_STR,4,1252)DATEPART( "yyyy" , getdate() )+ RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" , getdate() ), 2)  + RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , getdate() ), 2) +".csv"

This works out great as a variable, but what if I want to pass this function as a parameter from SSMS? Is there a way for Parameters to be evaluated as a expression? I attempted passing the parameter into a variable to achieve the desired effect to no available.

Am I missing something here, or should I just be hard coding this into a variable / calculating this elsewhere and pulling it into SSIS from a table?

Hadi
  • 36,233
  • 13
  • 65
  • 124
sc305495
  • 249
  • 3
  • 11

2 Answers2

0

If you want to retrieve the value from a database function and store in a variable you can use the Execute SQL Task.

You can combine variables with expressions in other variables along with scripts. Where you perform the calculation is your choice.

mheptinstall
  • 2,109
  • 3
  • 24
  • 44
0
  1. First you have to create 2 variables p_Date of type DateTime and Filename of type String
  2. In the properties tab set EvaluateAsExpressions = True for the variable Filename and Use the following expressions

    "EmployeeCount_"+(DT_STR,4,1252)DATEPART( "yyyy" , @[User::p_Date]  )+ RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" ,  @[User::p_Date]  ), 2)  + RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" ,  @[User::p_Date] ), 2) +".csv"
    

enter image description here

enter image description here

  1. Add an Execute SQL Task
  2. Set ResultSetproperty to Single Row
  3. Fill the SqlCommand and Connection property

enter image description here

  1. Go to ResultSet Tab , Add a New Result Set like shown in the image below

enter image description here

Note: 0 in the image above means the index of column from the sql command your provided

Hadi
  • 36,233
  • 13
  • 65
  • 124