Exports have random double quotes - sql-server

Why does the same field in different records have double quotes? Whenever the first field begins with double quote it is also padded with spaces to the right. Also, notice that some last fields end with double quote and others do not. Another weird thing is when exporting to Flat File, Code Page 65001(UTF-8) is auto selected and would not export. Perhaps it is sensing this in the data? 1252 ANSI Latin 1 works for the example below. There is no difference if I used “ for text exported CSV or not. Output is the same. The table data does not have quotes. Tbl Def 1
Tbl Def2

Related

Varchar fields containing a single double quote get exported with two double quotes from snowflake web UI

I have a table with a single Varchar column and a row with value A”B”C .
While downloading it from snowflake UI as a CSV file the result shows A””B””C
.
In this case if you are using Data Unloading feature, you need to use File format in the copy into statement.
In the file format you need to use the option "FIELD_OPTIONALLY_ENCLOSED_BY "
Ref - https://docs.snowflake.com/en/user-guide/data-unload-considerations.html#empty-strings-and-null-values
When a field contains this character, escape it using the same character. For example, if the value is the double quote character and a field contains the string "A", escape the double quotes as follows: ""A"".

Unable to get where clause to work with text containing a single quotation

I am working with some geo-spatial (string) data that i have been saving into an SQL server database, whenever my data has had a single quote within the string i am saving, i have tried to escape this by padding the single quote. Though this allows me to save the text into my database, when i try to use a where clause to find locations which have been had an escape sequence applied to them, the where clause does not seem to pick them up.
For example
SELECT * from tb_test WHERE Address = 'Abbey Gardens, St John''s Wood, London, NW8';
Will produce an empty table, even if this record exists. The only want i have been able to get this to work was by using LIKE to match the pattern of my text which does not include the quotation (see below).
SELECT * from tb_test WHERE Address LIKE 'Abbey Gardens'
Is there any reason as to why SQL does not pick up on the full Address ? and if so how can i get it to?
SELECT * from tb_test WHERE Address = 'Abbey Gardens, St John''s Wood,
London, NW8'; Will produce an empty table, even if this record exists.
The quotes are proper in the literal so it seems the actual column value does not match the literal value. This could be due to trailing whitespace (e.g. tab, newline, etc.). Check the raw binary value of the column for unexpected characters:
SELECT CAST(Address AS varbinary(MAX)), *
FROM tb_test
WHERE Address LIKE 'Abbey Gardens%';

Netezza CSV load ignore comma within value

I am loading a CSV file in Netezza. One of the columns in this file has value like: $500,000-$749,999.
Even though this value is enclosed within double quotes, Netezza is not ignoring the comma. It throws an error like - expected end of row, "999".
There are two more columns after this field in the file. I tried adding EscapeChar ',' but it again gave an error that Delimeter and EscapeChar cannot have the same character.
Have anyone faced similar issue?
Workaround:
I can add 2 two more columns in my table, but then it would fail where field do not have comma value in it.
Try setting the QuotedValue option to DOUBLE
https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.1/com.ibm.nz.load.doc/r_load_quotedvalue.html
Also, if all your columns are quoted, you could also set the requirequotes option to true
https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.1/com.ibm.nz.load.doc/r_load_requirequotes.html

SSIS Text Qualifier not working correctly

I have a CSV file I am importing through SSIS.Below is an sample of the data in my file
"MEM1001","OTHER","P" ,20101001,20781231,,20781231,20101001,
"Medic","General >21" ,
"A100100" ,"2210",20101001,20781231
I have added , as column delimiter and " as Text Qualifier in the connection manager.
But columns like "P" ,"Medic","General >21" ,"A100100" , are still coming enclosed with double quotes when I preview the data while rest the of the string columns are coming without double quotes.
I am guessing it has something to do with the spaces after the quotes.
Can somebody explain why this is happening and how can i make this columns to come without double quotes while importing the data from file to table.
I just stumbled across this post, I had the same issues, I was trying around and could not find any other solution.
The text qualifier " only works in csv files, when the quote is directly after the colon, no space after the colon and the text identifier/qualifier. I have no idea why.
If you aren't able to fix the input data, an option would be to create a derived column and to replace the double quotes.
This worked for me:
How to replace double quotes in derived column transformation?
Trim(REPLACE(COLA, "\"", ""))
You should also add the Trim(), otherwise you have empty spaces before and maybe after the word. This could be problematic in a merge join (in my case it was).
I don't know why this extra spaces cause this issue.
Here is what I would do. It may not be the best idea, but it should work.
You will need to add script task before data flow task that would replace all " ," and ", " to ",".
Thank you
Why not just go to the Connection Manager for that csv file, click on Columns, and under the Column delimiter box just enter a space followed by a comma? Worked for me.

SQlite error while updating the table

I am reading data from a table and updating into other table in SQLite. while reading it is not showing any error. But while it is updating it is showing error because the text i am going to update contains "You're" it is showing error for 're--> this apps' re. Any way to update with this special character?
Insert another single quote after You' so that the text becomes "You''re"
http://sqlite.org/lang_expr.html
A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal. C-style escapes using the backslash character are not supported because they are not standard SQL.

Resources