Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SSIS and parsing empty strings to integers

SSIS and parsing empty strings to integers

Scheduled Pinned Locked Moved Database
sql-serverquestiondatabasehelpcsharp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #1

    Using SQL Server 2008 R2 and SSIS, I just ran into a little problem. The source table has a VARCHAR column that contains mostly integers, also some NULLs, and some empty values. I'm copying rows to another table where the column is INTEGER, and SSIS is throwing: [ADO NET Destination [16]] Error: An exception has occurred during data insertion, the message returned from the provider is: The given value of type String from the data source cannot be converted to type int of the specified target column. After a few hours trying to narrow down what string value and which int column, I found that it is the empty strings causing the trouble. I have now wrapped the troublesome columns in CASE statements to replace empties with NULLs, but here's my question: If I execute the following in SSMS or via ADO.net

    CREATE TABLE dbo.NumTest (Num int)
    INSERT INTO dbo.NumTest VALUES ( '' )

    no Exception is thrown -- the resultant value is 0. So why the elephant does SSIS throw an Exception? Why is it trying to parse the string? Shouldn't it simply pass it to the database and react to any Exceptions? And how can I tell SSIS not to interfere?

    M S 2 Replies Last reply
    0
    • P PIEBALDconsult

      Using SQL Server 2008 R2 and SSIS, I just ran into a little problem. The source table has a VARCHAR column that contains mostly integers, also some NULLs, and some empty values. I'm copying rows to another table where the column is INTEGER, and SSIS is throwing: [ADO NET Destination [16]] Error: An exception has occurred during data insertion, the message returned from the provider is: The given value of type String from the data source cannot be converted to type int of the specified target column. After a few hours trying to narrow down what string value and which int column, I found that it is the empty strings causing the trouble. I have now wrapped the troublesome columns in CASE statements to replace empties with NULLs, but here's my question: If I execute the following in SSMS or via ADO.net

      CREATE TABLE dbo.NumTest (Num int)
      INSERT INTO dbo.NumTest VALUES ( '' )

      no Exception is thrown -- the resultant value is 0. So why the elephant does SSIS throw an Exception? Why is it trying to parse the string? Shouldn't it simply pass it to the database and react to any Exceptions? And how can I tell SSIS not to interfere?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      This is why we rip the T out of ETL, load the source into a staging table where every field is varchar and use a stored proc to do the transforms. SSIS is not alone in these idiotic inconsistencies, Biztalk and most of the big players in ETL also have them. It is also way easier to debug and test the transforms using a proc!

      Never underestimate the power of human stupidity RAH

      P 1 Reply Last reply
      0
      • M Mycroft Holmes

        This is why we rip the T out of ETL, load the source into a staging table where every field is varchar and use a stored proc to do the transforms. SSIS is not alone in these idiotic inconsistencies, Biztalk and most of the big players in ETL also have them. It is also way easier to debug and test the transforms using a proc!

        Never underestimate the power of human stupidity RAH

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I hear ya. This is my first time (eight months now) using SSIS and I don't like it. Previously I always used code. I'm doing a lot more pieces of this SSIS with "Script Tasks" -- C# code.

        M 1 Reply Last reply
        0
        • P PIEBALDconsult

          I hear ya. This is my first time (eight months now) using SSIS and I don't like it. Previously I always used code. I'm doing a lot more pieces of this SSIS with "Script Tasks" -- C# code.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          I had a class called filehandler, used in c# apps to load csv files, when we first started using SSIS I just hacked that class into the script objects, always intending to move to the SSIS data objects. It never actually happened, they are still using that class and a proc to do the transforms so SSIS is just an execution and scheduling shell.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • P PIEBALDconsult

            Using SQL Server 2008 R2 and SSIS, I just ran into a little problem. The source table has a VARCHAR column that contains mostly integers, also some NULLs, and some empty values. I'm copying rows to another table where the column is INTEGER, and SSIS is throwing: [ADO NET Destination [16]] Error: An exception has occurred during data insertion, the message returned from the provider is: The given value of type String from the data source cannot be converted to type int of the specified target column. After a few hours trying to narrow down what string value and which int column, I found that it is the empty strings causing the trouble. I have now wrapped the troublesome columns in CASE statements to replace empties with NULLs, but here's my question: If I execute the following in SSMS or via ADO.net

            CREATE TABLE dbo.NumTest (Num int)
            INSERT INTO dbo.NumTest VALUES ( '' )

            no Exception is thrown -- the resultant value is 0. So why the elephant does SSIS throw an Exception? Why is it trying to parse the string? Shouldn't it simply pass it to the database and react to any Exceptions? And how can I tell SSIS not to interfere?

            S Offline
            S Offline
            S Douglas
            wrote on last edited by
            #5

            The problem you are experiencing is a data type issue. The source is varchar, which means SSIS read and mapped the source adaptor to varchar and its output column to varchar. Inserting that varchar into the int caused your problem. To prevent this issue, in the data flow task -> Right click on the source -> scroll down to “Show Advanced Editor” Select “Input and Output Properties” Navigate down to “Output Columns” Locate the column in question and change the data type to something more appropriate such as “four-byte signed integer [DT_I4]” SSIS tries to guess what the source data type is and land it in the same data type without knowing everything in advance. SSMS builds the query first with the set of data then does the insert, so it knows to recast the data to the proper type. You could also change the error handling of the destination object to ignore the error. While this works as well it could lead to other issues and is less than desirable.


            Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups