SSIS Variable Changing Time Component











up vote
1
down vote

favorite












I have a SSIS Variable named "DestinationDirectory" that has the following Expression:



@[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) GETDATE() ),1,19),":","")


It returns for example:



C:Finance Extract2018-11-10 125913


I then have a heap of other variables such as the one below named "DestinationFileAdjustment" that work off "DestinationDirectory". It has the following expression:



@[User::DestinationDirectory] 
+ "\Adjustment_"
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
+ "_"
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "_"
+ (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
+ ".csv"


What is supposed to happen is a file be created within that directory. The problem I'm experiencing is each time @DestinationDirectory is referred to, it is returning a different time value (e.g. C:Finance Extract2018-11-10 125914) and errors out because the directory does not exist.



Is there a way I can set that variable at run-time and it retain the same time value each and every time it is referred to?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a SSIS Variable named "DestinationDirectory" that has the following Expression:



    @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) GETDATE() ),1,19),":","")


    It returns for example:



    C:Finance Extract2018-11-10 125913


    I then have a heap of other variables such as the one below named "DestinationFileAdjustment" that work off "DestinationDirectory". It has the following expression:



    @[User::DestinationDirectory] 
    + "\Adjustment_"
    + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
    + "_"
    + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
    + "_"
    + (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
    + ".csv"


    What is supposed to happen is a file be created within that directory. The problem I'm experiencing is each time @DestinationDirectory is referred to, it is returning a different time value (e.g. C:Finance Extract2018-11-10 125914) and errors out because the directory does not exist.



    Is there a way I can set that variable at run-time and it retain the same time value each and every time it is referred to?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a SSIS Variable named "DestinationDirectory" that has the following Expression:



      @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) GETDATE() ),1,19),":","")


      It returns for example:



      C:Finance Extract2018-11-10 125913


      I then have a heap of other variables such as the one below named "DestinationFileAdjustment" that work off "DestinationDirectory". It has the following expression:



      @[User::DestinationDirectory] 
      + "\Adjustment_"
      + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
      + "_"
      + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
      + "_"
      + (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
      + ".csv"


      What is supposed to happen is a file be created within that directory. The problem I'm experiencing is each time @DestinationDirectory is referred to, it is returning a different time value (e.g. C:Finance Extract2018-11-10 125914) and errors out because the directory does not exist.



      Is there a way I can set that variable at run-time and it retain the same time value each and every time it is referred to?










      share|improve this question













      I have a SSIS Variable named "DestinationDirectory" that has the following Expression:



      @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) GETDATE() ),1,19),":","")


      It returns for example:



      C:Finance Extract2018-11-10 125913


      I then have a heap of other variables such as the one below named "DestinationFileAdjustment" that work off "DestinationDirectory". It has the following expression:



      @[User::DestinationDirectory] 
      + "\Adjustment_"
      + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
      + "_"
      + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
      + "_"
      + (DT_STR, 4, 1252) DATEPART("yyyy" , GETDATE())
      + ".csv"


      What is supposed to happen is a file be created within that directory. The problem I'm experiencing is each time @DestinationDirectory is referred to, it is returning a different time value (e.g. C:Finance Extract2018-11-10 125914) and errors out because the directory does not exist.



      Is there a way I can set that variable at run-time and it retain the same time value each and every time it is referred to?







      sql-server ssis






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 2:03









      Philip

      547418




      547418
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Since you're using GETDATE() in your expression, I'm guessing that you're using the time that the package begins in the "DestinationDirectory" variable? If so, using the @[System::StartTime] system variable for the expression in this variable (example below) will provide this time and be consistent throughout the execution of the package.



          @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) @[System::StartTime]),1,19),":","")





          share|improve this answer

















          • 1




            Thank you for that, good piece of advice,.
            – Philip
            Nov 13 at 0:11


















          up vote
          1
          down vote













          What I finished up doing to get around this was to have a Script Task and the following code within it:



          Dts.Variables("User::DestinationDirectory").Value = Dts.Variables("User::SourceDirectory").Value.ToString + "\" + Replace(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ":", "")


          That hard coded the value for the variable nicely.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235413%2fssis-variable-changing-time-component%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Since you're using GETDATE() in your expression, I'm guessing that you're using the time that the package begins in the "DestinationDirectory" variable? If so, using the @[System::StartTime] system variable for the expression in this variable (example below) will provide this time and be consistent throughout the execution of the package.



            @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) @[System::StartTime]),1,19),":","")





            share|improve this answer

















            • 1




              Thank you for that, good piece of advice,.
              – Philip
              Nov 13 at 0:11















            up vote
            1
            down vote



            accepted










            Since you're using GETDATE() in your expression, I'm guessing that you're using the time that the package begins in the "DestinationDirectory" variable? If so, using the @[System::StartTime] system variable for the expression in this variable (example below) will provide this time and be consistent throughout the execution of the package.



            @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) @[System::StartTime]),1,19),":","")





            share|improve this answer

















            • 1




              Thank you for that, good piece of advice,.
              – Philip
              Nov 13 at 0:11













            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Since you're using GETDATE() in your expression, I'm guessing that you're using the time that the package begins in the "DestinationDirectory" variable? If so, using the @[System::StartTime] system variable for the expression in this variable (example below) will provide this time and be consistent throughout the execution of the package.



            @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) @[System::StartTime]),1,19),":","")





            share|improve this answer












            Since you're using GETDATE() in your expression, I'm guessing that you're using the time that the package begins in the "DestinationDirectory" variable? If so, using the @[System::StartTime] system variable for the expression in this variable (example below) will provide this time and be consistent throughout the execution of the package.



            @[User::SourceDirectory] + "\" + REPLACE(SUBSTRING((DT_WSTR,35)((DT_DBTIMESTAMPOFFSET, 7) @[System::StartTime]),1,19),":","")






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 at 18:33









            userfl89

            1,01159




            1,01159








            • 1




              Thank you for that, good piece of advice,.
              – Philip
              Nov 13 at 0:11














            • 1




              Thank you for that, good piece of advice,.
              – Philip
              Nov 13 at 0:11








            1




            1




            Thank you for that, good piece of advice,.
            – Philip
            Nov 13 at 0:11




            Thank you for that, good piece of advice,.
            – Philip
            Nov 13 at 0:11












            up vote
            1
            down vote













            What I finished up doing to get around this was to have a Script Task and the following code within it:



            Dts.Variables("User::DestinationDirectory").Value = Dts.Variables("User::SourceDirectory").Value.ToString + "\" + Replace(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ":", "")


            That hard coded the value for the variable nicely.






            share|improve this answer

























              up vote
              1
              down vote













              What I finished up doing to get around this was to have a Script Task and the following code within it:



              Dts.Variables("User::DestinationDirectory").Value = Dts.Variables("User::SourceDirectory").Value.ToString + "\" + Replace(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ":", "")


              That hard coded the value for the variable nicely.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                What I finished up doing to get around this was to have a Script Task and the following code within it:



                Dts.Variables("User::DestinationDirectory").Value = Dts.Variables("User::SourceDirectory").Value.ToString + "\" + Replace(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ":", "")


                That hard coded the value for the variable nicely.






                share|improve this answer












                What I finished up doing to get around this was to have a Script Task and the following code within it:



                Dts.Variables("User::DestinationDirectory").Value = Dts.Variables("User::SourceDirectory").Value.ToString + "\" + Replace(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ":", "")


                That hard coded the value for the variable nicely.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 3:14









                Philip

                547418




                547418






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235413%2fssis-variable-changing-time-component%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python