SSIS - converting string to HH:MM:SS












0















I am trying to read flat file with some data and I need to convert some columns to time type in the format of HH:MM:SS.



Below is the example how they are stored in the file (on the left) and how I want them to see in the database (on the right).




846 ---> 08:46:00



1323 ---> 13:23:00




I am performing following transformations:




  • if NA value appears, I am converting it to NULL (with Derived column)


  • then I am concatenating it to string in format of HH:MM:SS (using Derived Column)



    LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"



  • then I am converting it to the type DT_DBTIME2 with scale of 0 (using Data Conversion):



enter image description here



And this last step makes the package falling. Here is error message:




[Data Conversion [20]] Error: Data conversion failed while converting
column "ArrTime" (166) to column "Copy of ArrTime" (27). The
conversion returned status value 2 and status text "The value could
not be converted because of a potential loss of data.".




I am not very experienced in SSIS, but I really cannot see any reason for such an error.



When I tried to perform it without conversion, everything had gone fine.



Can anybody help me with that?



Greetings,



Chris.










share|improve this question














bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I am trying to read flat file with some data and I need to convert some columns to time type in the format of HH:MM:SS.



    Below is the example how they are stored in the file (on the left) and how I want them to see in the database (on the right).




    846 ---> 08:46:00



    1323 ---> 13:23:00




    I am performing following transformations:




    • if NA value appears, I am converting it to NULL (with Derived column)


    • then I am concatenating it to string in format of HH:MM:SS (using Derived Column)



      LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"



    • then I am converting it to the type DT_DBTIME2 with scale of 0 (using Data Conversion):



    enter image description here



    And this last step makes the package falling. Here is error message:




    [Data Conversion [20]] Error: Data conversion failed while converting
    column "ArrTime" (166) to column "Copy of ArrTime" (27). The
    conversion returned status value 2 and status text "The value could
    not be converted because of a potential loss of data.".




    I am not very experienced in SSIS, but I really cannot see any reason for such an error.



    When I tried to perform it without conversion, everything had gone fine.



    Can anybody help me with that?



    Greetings,



    Chris.










    share|improve this question














    bumped to the homepage by Community 16 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I am trying to read flat file with some data and I need to convert some columns to time type in the format of HH:MM:SS.



      Below is the example how they are stored in the file (on the left) and how I want them to see in the database (on the right).




      846 ---> 08:46:00



      1323 ---> 13:23:00




      I am performing following transformations:




      • if NA value appears, I am converting it to NULL (with Derived column)


      • then I am concatenating it to string in format of HH:MM:SS (using Derived Column)



        LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"



      • then I am converting it to the type DT_DBTIME2 with scale of 0 (using Data Conversion):



      enter image description here



      And this last step makes the package falling. Here is error message:




      [Data Conversion [20]] Error: Data conversion failed while converting
      column "ArrTime" (166) to column "Copy of ArrTime" (27). The
      conversion returned status value 2 and status text "The value could
      not be converted because of a potential loss of data.".




      I am not very experienced in SSIS, but I really cannot see any reason for such an error.



      When I tried to perform it without conversion, everything had gone fine.



      Can anybody help me with that?



      Greetings,



      Chris.










      share|improve this question














      I am trying to read flat file with some data and I need to convert some columns to time type in the format of HH:MM:SS.



      Below is the example how they are stored in the file (on the left) and how I want them to see in the database (on the right).




      846 ---> 08:46:00



      1323 ---> 13:23:00




      I am performing following transformations:




      • if NA value appears, I am converting it to NULL (with Derived column)


      • then I am concatenating it to string in format of HH:MM:SS (using Derived Column)



        LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"



      • then I am converting it to the type DT_DBTIME2 with scale of 0 (using Data Conversion):



      enter image description here



      And this last step makes the package falling. Here is error message:




      [Data Conversion [20]] Error: Data conversion failed while converting
      column "ArrTime" (166) to column "Copy of ArrTime" (27). The
      conversion returned status value 2 and status text "The value could
      not be converted because of a potential loss of data.".




      I am not very experienced in SSIS, but I really cannot see any reason for such an error.



      When I tried to perform it without conversion, everything had gone fine.



      Can anybody help me with that?



      Greetings,



      Chris.







      ssis time






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 19 '18 at 10:47









      Krzysztof PiotrowskiKrzysztof Piotrowski

      1




      1





      bumped to the homepage by Community 16 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 16 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Update:



          It was related to specific construction of dataset.



          if the time was in range from 00:00:00 to 00:59:00 it was presented as follows (examples):




          4 ---> 00:04:00



          57 ---> 00:57:00




          So the previously posted code did not even take such a case into consideration.



          The code solving the problem is following:



          LEN(ArrTime) == 1 ? "00:0" + ArrTime + ":00" : (LEN(ArrTime) == 2 ? "00:" + ArrTime + ":00" : (LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"))


          Now I solved the problem and all works fine.



          Maybe someone will need such solution ;)






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "182"
            };
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fdba.stackexchange.com%2fquestions%2f207268%2fssis-converting-string-to-hhmmss%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Update:



            It was related to specific construction of dataset.



            if the time was in range from 00:00:00 to 00:59:00 it was presented as follows (examples):




            4 ---> 00:04:00



            57 ---> 00:57:00




            So the previously posted code did not even take such a case into consideration.



            The code solving the problem is following:



            LEN(ArrTime) == 1 ? "00:0" + ArrTime + ":00" : (LEN(ArrTime) == 2 ? "00:" + ArrTime + ":00" : (LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"))


            Now I solved the problem and all works fine.



            Maybe someone will need such solution ;)






            share|improve this answer




























              0














              Update:



              It was related to specific construction of dataset.



              if the time was in range from 00:00:00 to 00:59:00 it was presented as follows (examples):




              4 ---> 00:04:00



              57 ---> 00:57:00




              So the previously posted code did not even take such a case into consideration.



              The code solving the problem is following:



              LEN(ArrTime) == 1 ? "00:0" + ArrTime + ":00" : (LEN(ArrTime) == 2 ? "00:" + ArrTime + ":00" : (LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"))


              Now I solved the problem and all works fine.



              Maybe someone will need such solution ;)






              share|improve this answer


























                0












                0








                0







                Update:



                It was related to specific construction of dataset.



                if the time was in range from 00:00:00 to 00:59:00 it was presented as follows (examples):




                4 ---> 00:04:00



                57 ---> 00:57:00




                So the previously posted code did not even take such a case into consideration.



                The code solving the problem is following:



                LEN(ArrTime) == 1 ? "00:0" + ArrTime + ":00" : (LEN(ArrTime) == 2 ? "00:" + ArrTime + ":00" : (LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"))


                Now I solved the problem and all works fine.



                Maybe someone will need such solution ;)






                share|improve this answer













                Update:



                It was related to specific construction of dataset.



                if the time was in range from 00:00:00 to 00:59:00 it was presented as follows (examples):




                4 ---> 00:04:00



                57 ---> 00:57:00




                So the previously posted code did not even take such a case into consideration.



                The code solving the problem is following:



                LEN(ArrTime) == 1 ? "00:0" + ArrTime + ":00" : (LEN(ArrTime) == 2 ? "00:" + ArrTime + ":00" : (LEN(ArrTime) == 3 ? "0" + SUBSTRING(ArrTime,1,1) + ":" + SUBSTRING(ArrTime,2,2) + ":00" : SUBSTRING(ArrTime,1,2) + ":" + SUBSTRING(ArrTime,3,2) + ":00"))


                Now I solved the problem and all works fine.



                Maybe someone will need such solution ;)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 19 '18 at 15:44









                Krzysztof PiotrowskiKrzysztof Piotrowski

                1




                1






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Database Administrators Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f207268%2fssis-converting-string-to-hhmmss%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

                    Liste der Baudenkmale in Friedland (Mecklenburg)

                    Single-Malt-Whisky

                    Czorneboh