Why can't bulk insert format csv? - sql

I have this code:
BULK INSERT [custdb].[dbo].[TB_T_DISP_PARTY] FROM 'd\DB\dbo.TB_T_DISP_PARTY.csv' WITH ( FIRSTROW = 2, FORMAT = 'CSV' );
And then I get this error
'Msg 102, Level 15, State 1, Line 6
Incorrect syntax near'FORMAT'.'
Can somebody tell me how to fix this error?

It is just bcoz of Version Difference
FORMAT = 'CSV' Applies to: SQL Server 2017 + Versions

Related

SQL Server Bulk Insert error - data conversion error (type mismatch or invalid character for the specified codepage)

I'm not a pro in this but I'm trying to do a bulk insert (from csv to SQL Server) but I'm getting some errors:
Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (Year).
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Here is the code I have used:
BULK INSERT [dbCen_Staging].dbo.[dc1]
FROM "C:\Newfolder\dc.csv"
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
MAXERRORS = 0,
--DATAFILETYPE = 'widechar',
BATCHSIZE=250000,
KEEPIDENTITY
)
GO
So wondering why I'm making a mistake, or if anyone else has a better idea on how to insert a few csv files with 900 millions rows each to SQL Server table. Any on-premise or Azure cloud solution maybe? Because speed matters a lot.
Thanks all

How to solve the error_syntax error near '< '

Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '<'.
I got the above error message every time I tried to execute the below query.
UPDATE [dbo].[FM1]
SET [Datum] = <Datum, smalldatetime,>
,[Gesamtzeit] = <Gesamtzeit, nvarchar(5),>
You can try this no need to specify datatype here.
UPDATE [dbo].[FM1]
SET [Datum] = 'YourValue'
,[Gesamtzeit] = 'YourValue'
where ...

Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '‌'. insert statement SQL Server

Hi i am getting this error Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '‌' and i dont know from where is the problem. That is the code and also i attached a screenshot.
USE CobornSalesDB;
GO
INSERT INTO SalesActivity
VALUES ('AC00001','05-12-2016','AG16170','C000001',
'P0001','S00002'‌​,1,200000.00,NULL,‌1.2220,20,100000.00,
'12-25-2016','12-30-2016','12-31-2016','A000001','PR00001');
GO
![SCREENSHOT][1]
You have a hidden character
If I convert to ANSI in NotePad++
INSERT INTO
SalesActivity
VALUES
(
'AC00001',
'05-12-2016',
'AG16170',
'C000001',
'P0001',
'S00002'‌​, --this bad boy
1 ,
200000.00,
NULL,
1.2220,
20 ,
100000.00,
'12-25-2016',
'12-30-2016',
'12-31-2016',
'A000001',
'PR00001');
GO

SQL Error near the word 'go'

Why does SQL Server report that this statement isn't correct?
use DIGITECH
go
select *
from kunde as k
left join adresse as a on k.FK_AdID = a.AdID
where Name = 'Dirk'
go
SQL displays this error (in German):
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Translated to english:
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
As other have pointed out, GO is the default batch delimiter for tools like Management Studio or sqlcmd. SQL Server does not understand GO, the tools use it to separate batches and send individual batches to SQL Server. You probably took an entire .sql file and executed in your app.
You can use a library like DbUtilSqlCmd which understands the sqlcmd delimiters (GO), and other sqlcmd specific syntax like :setvar, and execute your .sql file through it.
Can you specify the database in the query and avoid the go statements? For example:
select * from DIGITECH.dbo.kunde as k
left join DIGITECH.dbo.adresse as a
on k.FK_AdID = a.AdID
where Name = 'Dirk'

inserting multiple values into a single cell using sql 2005

I have the typical table:
LSRNbr BatchNbr
111 1212
111 1414
And the query should return:
LSRNbr BatchNbr
111 1212, 1414
I was browsing for a solution to this and I found these two:
Solution 1:
;WITH C AS
(
SELECT LSRNbr, BatchNbr FROM tblDTS_LSRBatch
)
SELECT Distinct LSRNbr,
STUFF((SELECT ';' + BatchNbr FROM tblDTS_LSRBatch WHERE LSRNbr = c.LSRNbr FOR XML PATH('')),1,1,'')
FROM C
error:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ';'.
Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 'XML'.
Solution 2:
SELECT
[LSRNbr], REPLACE(RTRIM((SELECT [BatchNbr] + ' ' FROM tblDTS_LSRBatch WHERE (LSRNbr = Results.LSRNbr ) FOR XML PATH (''))),' ',', ') AS NameValues
FROM tblDTS_LSRBatch Results
GROUP BY LSRNbr
error:
Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'XML'.
But none of them worked for me, see errors above please.
What could be the problem here?
I'm using Microsoft SQL Server 2005
These are syntax errors.
You'll learn more from figuring out the particular error yourself:
Take a look at the syntax tree
Take a look at some good examples of what you're trying to do
If you still have trouble, feel free to ask more questions