Exporting a VARCHAR(MAX) Field from SQL to Excel in SSIS - sql-server

I'm creating a SSIS Package to export Data from a SQL Server Table into an Excel Sheet. My Table has one column of datatype VARCHAR(MAX). And this column can have data as big as 30,000 characters sometimes. So I used a Data Conversion block to convert that column's DataType from it's original datatype text stream [DT_TEXT] to Unicode text stream [DT_NTEXT]. But when I execute the Package, I get this error An error occurred while setting up a binding for the "MyColumnName" column. The binding status was "DT_NTEXT".
I googled a lot but I couldn't get an answer to my problem. I'd appreciate all the help that I could get.

You can skip the data conversion task and just force the type when you extract from SQL Server SELECT CAST(MyBigColumn AS nvarchar(max)) As MyBigColumnUnicode but you're going to run into the problem that a cell in Excel cannot hold 100k characters.
Total number of characters that a cell can contain: 32,776
Excel specifications and limits

Related

SSIS does not recognize Arabic Characters

My source SQL database contains Arabic characters and the column is an Xml data type. I am trying to get the data flown from source sql to destination sql db. However, when the data flow happens, the column which contains Arabic characters turns into gibberish (unrecognizable characters - not question marks).
How do I transition data correct from the source table to destination table. I have tried using Collate Arabic_CI_AI_KS_WS and used data conversion to add NTEXT and it's still not working.
Appreciate any leads to the direction in resolving this issue.
Thank you

SSIS Data Flow OLE DB To Excel Nvarchar Size Issue

Hopefully, this is not an ignorant question as I am still working to build SSIS Skills.
I Have a package that takes an excel sheet and loads it into an SSMS SQL table so that I can run analysis and update statements to the data. I am now looking to load that SQL table back into an Excel sheet. I have made an excel sheet as a template of a replication of the SQL table.
The issue I am now having is I have a field named "Comment" that datatype is Nvarchar(MAX) in my SQL table. This column does contain NULL values as well. When I am trying to load these back to the Excel column I am having an error.
[Excel Destination [28]] Error: An error occurred while setting up a binding for the "Comment" column. The binding status was "DT_NTEXT".
I thought perhaps I could do a Data Conversion to a string with the max character (Which is 757) but it truncates and errors on that size.
This data came from an excel column so I would think I can load it back to a column.
Thanks for the help!!
Previously I thought that Excel does not allow exporting data with longer than 255 characters. After running several experiments, exporting DT_NTEXT values to Excel can be done using SSIS:
You should create an Excel file with one dummy row that contains long text values (> 255) then use this Excel as a destination. If the Excel contains previous data, make sure to add this dummy row directly after the file header and add ;IMEX=1 to the OLE DB connectionstring.

SSIS importing extra decimal values in to destination sql table from excel

I am trying to import "Financial data" from Excel files in to sql table. Problem I am facing is that My ssis package is incrementing decimal values. e.g -(175.20) from Excel is being loaded as "-175.20000000000005" in SQL.
I am using nVArChar (20) in destination SQL table. Images attached. What's the best data type in destination table. I have done a lot of reading and people seem to suggest decimal data but Package throws error for Decimal data type.Need help please.
Ended up changing the Data type to "Currency" in my SQL destination. Then added a data conversion task to change "DT_R8" data type from excel source to "currency[DT_CY]. This resolved the issue. could have used decimal or Numeric (16,2)data type in my destination as well but then i just went ahead with currency and it worked.
You could use a Derived Column Transformation in your Data Flow Task, with an expression like ROUND([GM],2) (you might need to replace GM with whatever your actual column name is).
You can then go to the Advanced Editor of the Derived Column Transformation and set the data type to decimal with a Scale of 2 on the 'Input and Output Properties' tab (look under 'Derived Column Output').
You'll then be able to use a decimal data type in your SQL Server table.

SQL Server 2014 SSIS Excel Source Task import to table date and text to numeric conversion issues

Using SQL Server 2014 SSIS to import an vendor supplied Excel file through the Excel Source Data Flow. Two issues I'm having related to data conversion to the SQL table.
In the file is a text column that has prices (numeric values) in it I can't not get it to transform into a numeric field (decimal(8,2)) in SQL. I have used the Data Conversion data flow task converting it to DT_NUMERIC and it fails to process the field. I have also tried to let it go through the Data Conversion task and converted through a Derived Column casting the field to Numeric. Both fail, I'm at a loss as to how to get this into the database in a Decimal/Numeric format.
In the same file are three date fields with dates that look like 07/18/2015 in Excel. I have tried similarly with the Data Conversion and Derived column to get the date into the database as SQL date formats. I have cast the dates at DT_DBDATE and DT_DBDATE and DT_DBTIMESTANP and neither has worked I have also tried taking the month day and year and rearranging them into the SQL date format with Substring/left/right functions to split the string. Also to no avail.
Here is what I tried:
Excel Source ---> Data Conversion ----> Derived Column -----> OLE DB Destination
In the excel source it recognized the date as text, I leave that be in the data conversion to deal with it in the Derived Column where I have tried.
a. (DT_DBDATE)("20" + RIGHT(TRIM(sale_start),2) + "-" + LEFT(TRIM(sale_start),2) + "-" + SUBSTRING(TRIM(sale_start),4,2)) - I have done this with and without the trim with same results. I have also used Right(sale_start,4).
b. (DT_DBDATE) sale_start
The SQL table is data type DATE. I have also changed it to DATETIME and used DT_DBTIMESTAMP in place of DT_DBDATE above.
I can't change the file I'm receiving it needs to process into the database the way it comes from the vendor. Looking at the data in excel there seems to be no reason it wouldn't be ok.
Any direction on bringing this data in would be much appreciated.
2.
I was able to figure this out although I don't completely understand what the connection setting is doing. Similarly with a XML file this connection setting wasn't necessary although some version of a derived column was, I the above I believe in my XML import.
For the EXCEL Solution:
1) In the Excel File connection I added IMEX=1 to the end of the connection under properties. So the connection string looked like this:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SSIS\Test.xls;Extended Properties="EXCEL 8.0;HDR=YES;IMEX=1";
2) Used the following script in the derived column:
ISNULL([Copy of expected_date]) ? NULL(DT_DATE) : (LEN(TRIM([Copy of expected_date])) == 0 ? NULL(DT_DATE) : (DT_DATE)((DT_DBDATE)TRIM([Copy of expected_date])))
Thanks for taking the time to respond.

SSIS: XML to Excel export, truncation may happen due to inserting data from data flow column with a length of 4000 to database column with length 255

I'm using SQL 2008 R2 & Excel of format xlsx. I'm trying to export data to Excel through XML source.Everything is working fine, than for columns where data is more than 255 characters. I get a warning:
truncation may happen due to inserting data from data flow column with
a length of 4000 to database column with length 255
I've tried changing registry and IMEX value as per the blog. This doesn't seem to help me. Also, for me connection string (Excel Connection Manager) is
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Extract_8202014.xlsx;Extended
Properties="EXCEL 12.0 XML;HDR=YES";
As per MDSN for memo type columns we should define datatype as longtext if table is getting created at run time. I've done same. But it's not helping.

Resources