Search code examples
sql-servervariablesssisetlsql-server-data-tools

ssis reset variable before reusing


I have a variable @[User::fileExist] within my ssis package which I use to return a result if a file exists.

It is defaulted to 0 then if a file exists it will return 1. I decided to re use this variable later on in the package how do I reset this variable before using it again


Solution

  • Using Expression Task

    SQL Server 2012 or newer

    You can use an expression task to achieve this. just add an expression task to your package and use the following expression

    @[User::fileExist] = 0
    

    Read more @:


    Using Script Task

    Or you can use a script task to achieve this, just add a script task to your package, choose this variable as a ReadWrite Variable and inside the script write the following code (you have to select Microsoft Visual Basic as script Language):

    Public Sub Main()
        Dts.Variables.Item("fileExist").Value = 0
    
        Dts.TaskResult = ScriptResults.Success
    
    End Sub