SSIS importing ragged right flat file - ssis

I am very new to SSIS development. Please help me
I have a ragged right flat file with no column names, which I need to import to sql server database.
The problem is, when importing these file using flat file connection manager, all the columns are stored as varchar. I have different columns like Amount (which should be a decimal data type), percentage (which should be a decimal data type), Date (which should be a date data type mm/dd/yyyy format).
For example, The amount field is loaded as 000012347834 . I need to change it to 123478.34
percentage field is loaded as 03246. I need it as 03.246 .
How can I do these conversions using SSIS.
Thank you in advance for your valuable time and help.

You can use the advanced editor on your connection manager to change the data types.
You can also use a data conversion task which is more along the lines of what SSIS is designed for... Transform is the T in ETL.
However most often if I have a lot of conversions to do on a text file import I will load into a staging table with all varchar and use a stored procedure to do the conversions.

Related

How to convert EXCEL to SQL (I have 143864 row and 100 column in excel) total 48,316 KB

I convert excel to csv first, then import to phpmyadmin only import 100 rows, I changed config.inc buffer size but still did not changed the result. Could you please help me ???
My main idea to do this, compare two tables on mysql workbench, I have one table already sql, i need excel to convert sql then i can use "compare schemas" creating EER Model of existing database.
Good you described the purpose of this approach. This way I can tell you in advance that it will not help to convert that Excel data to a MySQL table.
The model features (sync, compare etc.) all work on meta data only. They do not consider any table content. So instead you should do a textual comparison, by converting the table you have in the server to CSV.
Comparing such large documents is however a challenge. If you only have a few changes then using a diff tool (visual like Araxis Merge or diff on the command line) may help. For larger changesets a small utility app (may self written) might be necessary.

SSIS - Flat File Destination data formatting

If I have a column of type DT_DBDATE or DT_DBTIMESTAMP, and I write the data to a file using a Flat File Destination component, the resulting date formatting will YYYY-MM-DD HH:MM:SS. I've experimented with changing the package locale and changing the datatype in the Flat File Connection Manager, but these don't seem to have any effect.
What determines this format and is there any way I can change the default formatting?
PS. I know I can use Data Conversion and Derived Column components to change the data types/formats. The point is we have +150 packages and get too many errors when someone forgets to do the conversion or does it incorrectly.
We're using SSIS 2012.
I had a similar issue while using SSIS 2008 with SQL Server 2008 R2. If you are trying to generate a CSV file, I would recommend first, at the database level, to store the value in the desired format. This means, for instance, if you want to display a column where the current date is in the format YYYY-MM-DD, then you should use the appropriate code to store that value. Using T-SQL will be: convert(varchar(10), cast(GETDATE() as date), 126). Double check that the value was stored in the desired format by reading the table. Now it comes the tricky part: no matter what you are using in SSIS for transforming the dates, if you open the CSV using Excel, then Excel is going to display the dates using the format was set for the operating system. Don't panic, just don't save that file when you want to close it. Instead, if you open the CSV using Notepad or Notepad++, you should be able to see the date columns right in the format you used for storing them in the database.

SSIS: cannot convert between unicode and non-unicode string data types

I am working in SQL Server 2008 and BIDS (SSIS). I have a simple data flow task in which I'm importing a flat file into an OLE DB destination. On the OLE DB destination, I'm getting an error message, stating "cannot convert between unicode and non-unicode string data types".
Now, I know one solution method is to put a data conversion in between the flat file and the OLE DB destination. However, my concern is why this is even happening in the first place. In the connection manager for the given flat file, all columns are string (DT_STR) data types, and the Unicode option is unchecked. Similarly, all columns in the destination table (upon the inspection of the metadata in SSMS) are varchar data types. So, there is no nvarchar-to-varchar mapping going on at all.
Why is SSIS thinking that I have a unicode-to-nonunicode mapping happening? And, is there an easier way to resolve this than inserting a data conversion step for the columns that have this problem?
[Since I don't seem to be allowed to comment on the question, I'm having to put my question here.]
Have you checked the table you're trying to insert the data into to see if the columns in the table are varchar or nvarchar? The SSIS metadata could be out of sync with the database table.

Split columns in SSIS into a numeric part and the remainder of the column value

I'm trying to figure out how to convert my existing DTS files to DTSX hosted on a SQL 2005 server.
In my first try (first DTS) I'm already stuck.
I don't wanna look how things are done using DTS and wanna focus on the new DTSX techniques.
What has to be done.
Check if input file exists else exit.(not done yet)
Truncate destination table
Import file into DB
Report if everything was alright.
step import file is where I'm stuck. I have a fixed columns sized flat tekst file where housenumber and extension are in a single column. The Database has two columns for it.
I first tried a derived column but could find a check for splittng the (first) numeric part.
When searching for the use of regex i read about the "script component" which i read isn't compatible with SQL 2005.
Is there another possibility?
This brings me to a second question: Is it possible to use SQL Server Data Tools (SSDT) with SQL Server 2005.
You have a job ahead of you. You will need to use Derived Column transformations, so look them up. It will be helpful to add Data Viewers to your dataflows so you can see what data is moving through the flow, and what SSIS thinks is in there.
In your case, you are going to have to manipulate strings. There are two string data types, DT_STR and DT_WSTR (e.g., VARCHAR and NVARCHAR). SSIS is very particular about data types, and you may have to convert one type into the other using cast operations. E.g., (DT_WSTR, 50)Blah converts fifty characters from column Blah into DT_WSTR. The DT_STR type also needs to know the code page,. e.g. something like 1252.
You will likely need the SSIS version of Immediate If, which checks if a condition is true, and returns either one result or the other: Blah==100?1:0 The result of this will be a 1 for those records where column Blah equals 100, and 0 for all other records. You can nest these Immediate If statements, with one inside the next, inside the next, adn so forth.
You will need at least two new columns being created in the Derived Column widget, one for the numbers, and one for what follows. So here is one very painful way to do what you want. Use a string function to check whether the first character is a number, and then either return it, or don't. Do the same for the second character, etc.
Of course, I'm sure there's a better way to do this. Your toolbox consists of the functions in the Derived Column widget, so that's what you've got to work with. (Or, alternatively, you might do better in this case with a SQL UPDATE statement, which you would execute as a subsequent task in the Control Flow above, not in the Data Flow below.)
Fair warning: the SQL Server 2005 version of SSIS has many, many, many bugs and frustrations which were fixed or improved in later versions of SQL Server. Even if you just go to SQL Server 2008 you will save yourself many headaches.

Reading excel from DB (varbinary) in SSIS

First I'd like to say that I'm brand new to SSIS so bear with me if this is a very basic question. I've searched and cannot find an answer.
I need to read data from SQL Server that is stored in a varbinary column that contains an excel document. I then need to store this data into another table with the appropriate columns (pre-defined format).
My question is essentially... How do I read this varbinary data into something I can work with and then insert into another table?
You could use Export Column Transformation available within the Data Flow Task to read the varbinary data and then save it as a file on local disk where the SSIS package is running.
MSDN documentation about Export Column transformation.
Sample: The Export Column Transformation on BI Monkey
Using another data flow task, you can read the saved file and import the data into the table of your choice.