Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double quotes from excel query when copy/paste from Excel into SQL Server 2012

I have a query Excel in each of my rows, about 2000. When I copy paste all queries into SQL Server roughly 100 rows are showing a error. Might not even be an error but the query will paste into SQL Server with double quotes in front of entire query.

I have error checking in place so it has something to do with the data in my Excel sheet. My query pasted in SQL Server for instance:

"insert into

I cannot paste the entire query or any data, sorry.

Thank you for looking at this

like image 876
user3029609 Avatar asked Sep 29 '14 22:09

user3029609


People also ask

How escape double quotes in SQL query?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.

Does SQL accept double quotes?

Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes.


2 Answers

This occurs when a line has an embedded carriage return, it may happen in other situations as well. I just do a find/replace for double quotes in the resulting query, but you could also first paste it into Word then copy from there and it will paste without the quotes.

Alternatively, if it's just from embedded returns you could wrap your formula in a pair of SUBSTITUTE() functions to remove CHAR(13) and CHAR(10) if formula was in A1:

=SUBSTITUTE(SUBSTITUTE(A1,CHAR(13),""),CHAR(10),"")
like image 109
Hart CO Avatar answered Oct 21 '22 04:10

Hart CO


Actually a lot easier then all of the posts here, in another column do the following formula:

=CLEAN(MyCell)

like image 44
ShanksPranks Avatar answered Oct 21 '22 04:10

ShanksPranks