Domanda

I have an SSIS Package which should take data from a Flat File (txt). One of the fields should be an Unsigned Integer and i should load it to an SQL table. In the "Flat File Connection Manager Editor" i set the "Format" of the flat file to Fixed width (don't have any delimiters only a spec file with columns lengths. The field i am talking about should be 4 chars long (according to the definition). but in some values i get the "}" sign on the 4th char, for example: "010}" I trusted the definition and tried to load this value into an unsigned integer with no luck.

Does anyone recognize such a formatting? If you do, how can i load it into the proper data type?

thank you in advanced. Oren.

È stato utile?

Soluzione

There are several things that could be going wrong on your import. First you have to know the encoding of your original file:

How can I detect the encoding/codepage of a text file

The encoding will determine the actual size in bytes of your char and more importantly how each character is stored. You see, a unicode string of four chars can be anywhere from four bytes to 16 bytes(maybe more if you have compound characters) depending on the encoding. An int is usually four bytes(DT_I 4) but ssis offers you up to 32(I think). So when you're loading your unknown number of bytes into the predetermined unsigned int some stuff might be getting truncated and you end up with garbage values.

If your dont know or can't find the encoding I would assume it is UTF-8, but thats really not good practice. This is a little bit about it: http://en.wikipedia.org/wiki/UTF-8 you can also take a look at the unicode character sets for different encodings(UTF-8, UTF-16..) and look for the "}" character and its matching value. That might give you a hint as to why it is showing up.

Then your flat file source should match that type of encoding. Check(or uncheck) the Unicode check box to set it/ or pick a "Code Page" . Then load the value of that column into a string(of the right encoding), not an unsigned int.

Finaly when you know you have the right value, you can use a "Data Conversion" to cast it to an unsigned int, or anything else really.

EDIT: The "Data Conversion" will, as per its name, convert your imported value. That may not work, depending on how the original file was written. The "derived column" cast will be your other option, which won't change the actual value, just tell the compiler to interpret those bits as another type (unsigned int).

Altri suggerimenti

If I understand your question right . one of the ways is to use a "derived Column transformation". Choose to Add a new column in it.
If the data you are fetching is in DT_WSTR data type, you can use the following expression to get rid of '}' by ''. Then type cast it according to the field you want to load. Here I am using (DT_I4) Then Map the new column to the destination.

   (DT_I4) REPLACE(character_expression,searchstring,replacementstring)

Hope It helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top