CAST or CONVERT in Excel Query - ssis

How to use CAST or CONVERT in Excel Query ie in Excel Source Task. I wanted to conert a number to Text in the Excel Source Task itself using SQL Command option.

Best option is to use Data conversion between source and destination.
As in Excel source or destination connection manager we can CAST or CONVERT as in SQL.
Please add data trasformation task like below:
As like the Excel destination it can be any destination after transformation

There are many problems connected with excel files and data types. Sometimes it's very painful.
Check this out:
http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/355afd19-8128-4673-a9d1-9a5658b72e84
or this:
http://www.connectionstrings.com/excel
When I use xls files I often convert everything to text: IMEX=1 and then I use Data Conversion Task.
So I suggest to change your connection string to:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
And then you can do everything you want with data in SSIS.

Related

Change date format of data coming from flat file SSIS

I am reading data from a flat file and storing them in a OLE DB destination.
In the flat file, dates and in various formats
17/02/2014,
28-Apr-14,
30.06.14
I have used a Derived column transformation to check for empty columns and replace it with null. As far as I have seen SSIS and data base accepts 17/02/2014 format and 28-Apr-14, 30.06.14 are rejected.
I want to convert 28-Apr-14 and 30.06.14 to a valid format which DB accepts.
I have researched a bit and read that Script task can do it but I am not sure of the code how to check this.
Could you please guide which is the best way to do this.
Any suggestions/help is much appreciated.
Thanks
Rao
Check out my answer on the following question. This should work for you as well.
SSIS clean up date from csv file

How to convert data read from file form Windows-1250 to UTF-8 with SSIS

My SSIS code read file encoded as windows-1250 and put it do database. But I want to display it later in web application (UTF-8). How to transform it quickly?
I think that best option is SSIS conversion, but HOW?:)
When inserting data into the database, use 'DT_WSTR' as data type instead of 'DT_STR' in the SSIS package where 'W' in 'DT_WSTR' stands for Unicode.
Use 'nvarchar' as data type instead of 'varchar' in the database. It'll store your data in Unicode Format.

Ms access transfertext converting text in excel cvs to Currency

I am trying to import data from excel csv to MS Access. A column in csv has majority of values like "F0000123". Few Values are "E0000123". While importing this using transfertext to Text column in Access, F0000123 has changed to 123 and E0000123 has been imported as blank with datatype conversion failure. If importing to new blank (no columns defined) table F0000123 importing as $123 and again E0000123 has been imported as blank with datatype conversion failure. Please help why value starting with F have this issue.
Link the csv file as a table. Then create a query to read and convert (purify) the data.
Use this query as source for further processing of the date like appending data to other tables.

Junk characters at the beginning of file obtained via column transformations in SSIS

I need to export varbinary data to file. But, when I do it using Column Transformations in SSIS, the exported files are corrupt. There are few junk characters at the start of the file. On removing them, the file opens fine.
A similar post for BCP, says that these characters specify the data length.
Would like to know how to address this issue in SSIS?
Thanks
Export transformation is used for converting the varbinary to files.I have tried something similar using Adventure works which has image type of var-binary data.
Following Query is used for the Source query. I have Modified the query
since it does not have the full path to write image files.
SELECT [ProductPhotoID]
,[ThumbNailPhoto]
,'D:\SSISTesting\ThumnailPhotos\'+[ThumbnailPhotoFileName]
,[LargePhoto]
,'D:\SSISTesting\LargePhotos\'+[LargePhotoFileName]
,[ModifiedDate]
FROM [Production].[ProductPhoto]
Used the Export column transformation[also available in 2005 and
2008] and configured as follows.
Mapped rest of the columns to the destination.
After running package all the image files are written into the
respective folders[D:\SSISTesting\ThumnailPhotos\ and D:\SSISTesting\LargePhotos].
Hope this helps!

How to remove prefixed numbers from a varchar in SSIS?

I have an SSIS package which copy data from text file to a table in sql server.
I use 3 tasks for the same 1)Flatfile Source 2) Derived Column task, 3) SQL Destination task
In the 3rd task..I specify the table...into which I have to copy the data.
In that destination table..there is a column DESC..and it's of type varchar...and flat file contains data for this column as follows :- "01 planA".."04 plan C", "PlanJ".
I need to remove these prefixed numerics. I have a query as below..but I can use this in derived column task..as SSIS wont support PATINDEX.
SUBSTRING([DESC], PATINDEX('%[a-zA-Z]%',[DESC]), LEN([DESC])- PATINDEX('%[a-zA-Z]%',[DESC])+1)
Please help me.
You could do this in a Script task, using Regular Expressions. You'll need to reference System.Text.RegularExpressions then use the .NET Regex object to mimic the code above in the Input0_ProcessInputRow method.
Alternatively, send the raw data firstly to a SQL staging table and extract from there using PATINDEX as in your example, then push the cleaned version to your destination table.