Special characters in bulk insert query - sql

I need to pass this query :
BULK INSERT e-Alexie.ENTREPRISE\beulin-ma.Correspondance_RCU_PP
FROM '\\ST077283\C:\Users\P20M511\Documents\Test_RCU.csv';
but I get an error on the - character. I've tried with ^_-^_ but it didn't work
Any idea?

Related

Need to insert special character in string as insert script

I wanted to insert records having special character in snowflake.
Having record in source table :
order/date=2022-02-18/hour=12/85b3e2d8-0195-4238-b246-7ed6564ac464.json
I need to extract hour value i.e 12
I am able to extract the value using : cast(replace(substr(METADATA$FILENAME,28,2),'/','') as number)
But I need to create the insert script , I had tried :
'cast(replace(substr(METADATA$FILENAME,28,2),'/,'') as number)'
But getting error : FAILED CODE: 0 STATE: 22018 MESSAGE: Numeric value '5/' is not recognized
I tested your string in select and insert command as below:
select cast(replace(substr('order/date=2022-02-18/hour=12/85b3e2d8-0195-4238-b246-7ed6564ac464.json',28,2),'/','') as integer);
create table t1(c1 number);
insert into t1(c1) select cast(replace(substr('order/date=2022-02-18/hour=12/85b3e2d8-0195-4238-b246-7ed6564ac464.json',28,2),'/','') as integer);
If your issue is different, then share the exact command that you are executing and that's failing.
I got the solution :
Solution Snap shot
I wanted to insert this whole statement as string , I was facing issue due to special characters : / and '' .
Used backslash to resolve it.

Oracle SQL Syntax Error - missing comma

Below is a line of one of my insert statements, it keeps throwing a missing comma error - however Im either blind as a bat or going stupid?!
INSERT INTO barrister (barrister_id,firstname,surname,telephone,email_address)
VALUES (NEXT VALUE FOR sq_barrister, 'John', 'Smith',
'01392345465', 'john_smith#wtflawers.com');
Raul is right. NEXT VALUE FOR is from SQL Server. In Oracle, use
sq_barrister.nextval

Single and double quotes in SQL Server

I want to know exact reason why this error occur playing with quotes.
INSERT INTO table_check(name) VALUES('hello'hi') -- ERROR
INSERT INTO table_check(name) VALUES('hello''hi') -- RESULT:- hello'hi
INSERT INTO table_check(name) VALUES('hello'''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''hi') --RESULT:- hello''hi
INSERT INTO table_check(name) VALUES('hello'''''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''''hi') --RESULT:- hello'''hi
Single Quotes are Escaped by Doubling Them up.So whenever even number of Quotes are present, then we get the Result.
To Know The Behavior of Single Quotes Try to Run This Below Code:
Select '','''','''''','''''''',''''''''''
So,Single Quotes Should be Even Number Else We get error like:Unclosed quotation mark after the character string ') -- ERROR

BULK INSERT tab delimited data with missing value

I am trying to import a comma delimited data which is as follows.
5595,M,45,ABIQUIU,NEW MEXICO,132,EspanolaNM,40,AlbuquerqueHCS,.,NM,"ABIQUIU ,NM",324,1,1,0.1396
bulk insert Albuqurque from 'C:\AlbqurC.txt'
with
(
fieldterminator=',',
rowterminator='\n',
)
I am getting an error because there is a missing value "." after AlbuquerqueHCS
If I delete the missing value and replace that with a blank
5595,M,45,ABIQUIU,NEW MEXICO,132,EspanolaNM,40,AlbuquerqueHCS, ,NM,"ABIQUIU ,NM",324,1,1,0.1396
Import works fine,
Is there an option in sql BULK INSERT that will take care of missing values( "." ).... ?
Thanks in advance.

SQL Server Compact. There was an error parsing the query

I cannot figure out why this is not working. I get the same thing when I try to do an update query as well.
Here is the error " There was an error parsing the query. [ Token line number = 1,Token line offset = 43,Token in error = where ] "
Here is the actual Query INSERT INTO ads (title,price,body,enabled,where,interval,posted) VALUES('test','899','test',True,'Columbus',15,'11/25/2009 10:12:30 AM')
Where would be 'Columbus'
I am using visual studio express 2008 C#
WHERE is a reserved word, try wrapping it in brackets
INSERT INTO ads (title,price,body,enabled,[where],interval,posted)
VALUES('test','899','test',True,'Columbus',15,'11/25/2009 10:12:30 AM')
i think you should provide the value of the primary key in your insert statement,maybe SQL Server Compact databases are not generated automatically or you dont configure that.
I had the same problem this is the INSERT statement which was not working and got the same error:
INSERT INTO Customers(CustomerName,CustomerAddress,CustomerPhone)
VALUES ('Osama','Amman','656565')
this is the INSERT statement which was working fine:
INSERT INTO Customers(CustomerID,CustomerName,CustomerAddress,CustomerPhone)
VALUES ('4564','Osama','Amman','656565')
also if you have in your table columns with names have spaces like (Customer Name)
you must use brackets in your sqlCe statement as:
INSERT INTO Customers([CustomerID],[Customer Name],[Customer Address],[Customer Phone])
VALUES ('4564','Osama','Amman','656565')
also if you use SELECT SCOPE_IDENTITY() to get last record inserted in INSERT Statement
as:
INSERT INTO Customers(CustomerID,CustomerName,CustomerAddress,CustomerPhone)
VALUES ('4564','Osama','Amman','656565') SELECT SCOPE_IDENTITY()
don't use it...