Can't export SQL results as excel file when commas are in the description column text - sql

I am seeing an issue here. I have a sql database with over 10,000 records. There is a description column that contains user input from our support website. Some users put commas into their description for grammar purposes. When I go to export my sql results as a excel file, the commas in the user description text mess up the arrangement of the file. I need to export as what's in the SQL cells and not every time it sees a comma. Please help?

I believe if you wrap each output field in quotes, Excel should know to treat that as one field.
I hope this helps.

Thank you, I also did a replace within the database and replaced all the commas with a space, and then replaced all the tabs and line breaks with a space as well. The new line delimiter was making excel think it was a new cell. I opened the excel file in notepad++ to see all of the LF's and CRLF's and then just searched+replaced the ascii sequence of the two in SQL with a space. LF's, commas, and tabs, are all non important characters to preserve. Thanks again. -Chris

Related

How to discard (trim) double inverted quotes in CSV file on data prep?

I'm dealing with a csv file that contains double inverted quotes (since the data has commas in it). But Google sheets do not show me the double-quotes and hence i'm able to split the column by a delimiter (space in this case) properly, to retrieve its first word. The initial column values can be seen in the picture below.
However, in Data Prep when i upload the csv file, the column's double quotes are considered as a value and it causes extra work (if at all possible) in handling the resulting split data.
Is there a way in Data Prep where we can have the data displayed as in Google Sheets ?
You can "ignore" these double-quotes, and when running a job, untick the box of "include quotes", then these original quotes shall remain.
Not perfect, but could be a working workaround.

CSV Import to SQL Issues - text delimiter issues

All:
I've experienced CSV import issues MANY times. I have an extract from a client that's 1MM rows - the text fields (most of them anyway) have double-quote delimiters, but some do not (apologies for the small image, but please click to view larger version):
Also, there are numbers in this extract that have commas in them, and SQL identifies these as separate field values:
Clearly every data element should be in double-quotes (numeric or not), and at a minimum the numeric values should not be formatted with commas (i.e., 5,159 should be 5159).
Is there any hope of salvaging this file? The last resort is to bother the client to re-run this data but export as TSV or something useful.
Thank you in advance.

SQL Parse NVARCHAR Field

I am loading data from Excels into database on SQL Server 2008. There is one column which is in nvarchar data type. This field contains the data as
Text text text text text text text text text text.
(ABC-2010-4091, ABC-2011-0586, ABC-2011-0587, ABC-2011-0604)
Text text text text text text text text text text.
(ABC-2011-0562, ABC-2011-0570, ABC-2011-0575, ABC-2011-0588)
so its text with many sentences of this kind.
For each row I need to get the data ABC-####-####, respectivelly I only need the last part. So e.g. for ABC-2010-4091 I need to obtain 4091. This number I will need to join to other table. I guess it would be enough to get the last parts of the format ABC-####-####, then I should be able to handle the request.
So the example of given above, the result should be 4091, 0586, 0587, 0604, 0562, 0570, 0575, 0588 in the row instead of the whole nvarchar value field.
Is this possible somehow? The text in the nvarchar field differ, but the text format (ABC-####-####) I want to work with is still the same. Only the count of characters for the last part may vary so its not only 4 numbers, but could be 5 or more.
What is the best approach to get these data? Should I parse it in SSIS or on the SQL server side with SQL Query? And how?
I am aware this is though task. I appreciate every help or advice how to deal with this. I have not tried anything yet as I do not know where to start. I read articles about SQL parsing, but I want to ask for best approach to deal with this task.
Stackoverflow is about programming.
Sit down and start programming.
Ok, seriously. That is string parsing and the last part in brackets with multiple fields means no bulk import, it is not a standard CSV file.
Either you use SSIS in SQL Server and program the parsing there or.... you write a program for that.
String maniupation in SQL is the worst part of the language and I would avoid it.
So, yes, sit down and program a routine. Probable the fastest way.
If I understand correctly, "ABS-####-####" will be the value coming through in the column and the numeric part is variable in length.
If that is the case, maybe this will work.
Use a "Derived Column" transformation.
Lets say we call "ABC-####-####" = Column1
SUBSTRING("Column1",(FINDSTRING("Column1","-",2)+1),LEN(Column1)-(FINDSTRING("Column1","-",2)))
If I am not mistaken, that should give you the last # values in a new column no matter how long that value is.
HTH
I have worked this problem out with the following guides:
Split Multi Value Column into Multiple Records &
Remove Multiple Spaces with Only One Space

Getting long 'dirty' strings from SQL Server database into a 'clean' excel file

I Have a table in which comments are kept about clients. This is an open field and be very long and include line breaks.
When I try and export this to Excel, the data is misaligned. I'd like to return as much of the comment as possible in an excel cell, without anything like a line break.
Is there a way I could do this in Excel? (Find and replace)
Is there a way to structure my SQL query to only return what I can fit?
Or is there a better way?
I found the best way to deal with this is to enclose all suspect String columns with Speech marks "" and then in excel under the text to columns option make sure to select speech marks as a text qualifier.
This always worked for me.
Just be sure to remove speech marks from the string column in question otherwise it will split it again.
Another method i used was to used an obscure delimiter like an Ibar | which was not likely to be found in my data and by again using the Text to columns option i specified the IBar as the column separator which did just what i needed.
T

Comma delimited flat file source

I have a text file that is split using commas
Simple enough to do in SSIS but i have the following row in my source flat file:
Desc,Curr,Desc,ID,Quantity
05969A105 ,CU,BANCORP INC, THE DEL COMMON ,1,2126
there is a comma in my Desc column and im not sure how i can ignore that comma
AFAIK, you can't do anything in SSIS (or any other app that I have ever used) to handle this, because it is simply bad data. If you need to persist with comma delimiters then you will need to get the data provider to use text-delimiters, e.g. double-quotes, to wrap the data. SSIS can be told what is the text delimiter and will strip these chars off the data automatically.
Of course this may raise the issue of 'but the text may need to contain a double-quote!', in which case you would be better off getting the delimiter changed to something else, such as a tab or pipe.