SSIS - How to insert all values inside "" - ssis

there is a requirement for all the values integrating from SQL Server into a flat file (.csv) being inserted between a double quotation mark, such as 123 to be inserted as "123".
I am having such difficulty with this, i tried the derived columns with the script "\"\"" + [columnName] + "\"\"" but does not work at all.
Please be advised i need the column headers to have the same "" as well.
Many thanks!

If you mean you want to export data from SQL Server into a csv file using SSIS, and that you want the values to be double quoted, you just need to set the Text Qualifier property of your Destination connection to a double quote " character.

Related

Reading CSV file in SAP Data Services using double quotes as text delimiter - but only single double quotes in column value

I am reading a CSV file in SAP Data Services Designer and using (") as text delimiter. The client sometimes sends data that only has one double quote in a column, without a closing " which would mark the end of string. Because of this, it ends up reading next many rows as one single column, until it encounters the next ". I need to retain the " as text delimiter as that is also required. Is there a way to avoid the anomaly where the software only sees one "?
Thanks!

remove special characters " and ' from a column using SSIS

I have a csv which has a column called "Value" and in it there are a combination of strings & special characters.
Eg:
Value
abc
xyz
"
pqr
'
I want to replace the " and ' special characters with empty string "" in the output file.I used the derived column "Replace" function as
Replace(Replace(Value,"'",""),"\"","")
and it doesn't seem to work
tried this: in the derived column
Replace(Replace(Value,"'",""),"\"","")
I expect the output to be in a flat file with value column as
Value
"abc"
"xyz"
""
"pqr"
""
I want to replace the " and ' special characters with empty string ""
If you are looking to remove all quotations from all values then the derived column expression you are using is fine:
Replace(Replace(Value,"'",""),"\"","")
Since you mentioned that it doesn't seem to work, then you have to check many possible causes:
Check that the quotation is ' not `, try using the following expression
Replace(Replace(Replace(Value,"'",""),"\"",""),"`","")
If your goal is that all values in the destination flat file are enclosed within two double quotes: "abc", "" then you should edit the Flat File connection manager of the destination and set " as text qualifier and make sure that columns qualified property is set to true.
Text Qualifier in SSIS Example
Meaning of TextQualified attribute in flat file connections
As #Srikarmogaliraju mentioned, make sure that the derived column output is mapped in the destination

Using derived column for trailing zeros

I Have a column IN a SQL table that has these values('NONE','3.00','3.50'). When I export into comma delimited file USING SQL Server integration services I lose my trialing Zeros. I need the values AS is.
In the connection manager for the output file, make sure you have the column meta data set to either of the two STRING data types and then add the double quotes as a text qualifier.

SSIS Convert Between Unicode and Non-Unicode Error with LARGE Field

I have been struggling with this error now for days now and have tried everything I know. I have an SQL statement that pulls data from several tables into another table. The field in question is a NTEXT field from a SQL 2000 database, which I now import into a SQL 2008 R2 table that is NVARCHAR(MAX) data type because I though the issue was the NTEXT data type. However the SSIS package that is just an OLE DB Source (with 1 field) into an Excel Destination is still giving me the Unicode and Non-Unicode Error!! Several rows of data are over 8000 characters in length. Please help ...
After a lot of pain I finally came to the conclusion that Exporting to EXCEL is not possible so I turned to CSV. I used "Flat File Destination" object, pointed to a CSV that I had created with just the Headers. The Text Qualifier was set to double quotes. In the Columns section I set the Row delimiter to {CR}{LF} and the Column delimiter to Comma{,} because it is a CSV! The final part of the puzzle was to remove and double quotes, Carriage Returns and Line Feeds. I also had to convert the NTEXT field to VARCHAR(MAX) because REPLACE will not work with NTEXT. This is what I ended up with for the columns that had these "invalid characters".
REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(MAX),[MyNTEXTColumn]), CHAR(13),' '), '"', ''), CHAR(10),'') AS 'Corrected Output'
I replaced {CR} CHAR(13) with a space to that we could have it formatted well for the consumer. I hope this helps someone out one day.

Flat File to retain commas from SQL data

I’m importing a SQL view to SSIS using the Flat File Connection Manager. One of my columns in SQL has comma(s) in it. (123 Main St, Boston, MA) . When I import the data to SSIS, the commas within the column are being treated as delimiters, and my column is being broken into several columns. I have done a lot of research online, and have followed some workarounds which aren't working for me.
In SQL Server, I added double quotes around the values that have comma(s) in it.
' "'+CAST(a.Address as varchar(100))+'" '
So, 123 Main St, Boston, MA now reads “123 Main St, Boston, MA”
Then in my SSIS Flat File Connection Manager,
In the General tab:
Text Qualifier is set to “
Header Row Delimiter is set to {CR}-{LF}
In the columns tab:
Row delimiter is set to {LF}
Column delimiter is set to Comma {,}
And in the advanced Tab, all of my columns have the Text Qualified set to True.
After all of this, my column with commas in it, is still being separated into multiple columns. Am I missing a step? How can I get the SSIS package to treat my address column as one column and not break it out to several columns?
EDIT: Just to add more specifics. I am pulling from a SQL view that has double quotes around any field that has commas in it. I am then emailing that file and opening it in MS Excel. When I open it the file it read as follows:
123 Main St Boston MA" " (In three cells)
And I need it to read as
123 Main St, Boston, MA (in one cell)
Have a look of this - Commas within CSV Data
If there is a comma in a column then that column should be surrounded
by a single quote or double quote. Then if inside that column there is
a single or double quote it should have an escape charter before it,
usually a \
Example format of CSV
ID - address - name
1, "Some Address, Some Street, 10452", 'David O\'Brian'
Change every comma values with another unique delimiter which values haven't any of the characters inside,like : vertical bar ( | )
Change column delimiter to this new delimiter , and set text qualifier with double quote ( " )
You can automate the replace process using a Script Task before Dataflow Task for replacing delimiters. You can use replace script form here.
Also have a look of these resources.
Fixing comma problem in CSV file in SSIS
How to handle extra comma inside double quotes while processing a CSV file in SSIS
I ended up recreating the package, using the same parameters that are listed in my question. I also replaced this
' "'+CAST(a.Address as varchar(100))+'" '
with this in my SQL view
a.Address
And it now runs as desired. Not sure what was going on there. Thanks to everyone for their comments and suggestions.