SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Bulk Import error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dolphin123
Yak Posting Veteran

USA
54 Posts

Posted - 02/26/2013 :  10:55:32  Show Profile  Reply with Quote
Hi,

This is my source data in CSV format:


4,23,2AY5623,7235623
4,23,2GP1207,1451207
4,23,2GQ6689,4186689


Table:


CREATE TABLE [dbo].[Table1](
	[idCodeLevel] [int] NOT NULL,
	[idFirm] [int] NOT NULL,
	[valCodeFrom] [varchar](15) NOT NULL,
	[valCodeTo] [varchar](15) NOT NULL
) ON [PRIMARY]


This the code I am using to Bulk import:

USE Test
GO
 
TRUNCATE TABLE Table1
GO
 
BULK INSERT Table1
  FROM 'C:\Temp\test.csv'
  WITH (
    FIELDTERMINATOR = ',',
    MAXERRORS=0,
    ROWTERMINATOR = '\n'
  )
GO


Error I am getting is:

Msg 4864, Level 16, State 1, Line 2
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (idCodeLevel).


Can you please someone tell me why is it failing?
I googled and found out that I might have to use the format .fmt. But how can I convert a csv file to fmt. I have seen code to create fmt file from sql table.

Edited by - dolphin123 on 02/26/2013 10:59:52

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 02/26/2013 :  11:41:49  Show Profile  Reply with Quote
Do the column datatypes in the target table match the values in the CSV files?

Edited by - funk.phenomena on 02/26/2013 11:42:12
Go to Top of Page

dolphin123
Yak Posting Veteran

USA
54 Posts

Posted - 02/26/2013 :  11:49:06  Show Profile  Reply with Quote
It is matching.

It is failing on the first column in table Table1 which is mentioned above.
Column datatype is int and the the value I am passing is 4.
Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 02/26/2013 :  14:30:20  Show Profile  Reply with Quote
quote:
Originally posted by dolphin123

It is matching.

It is failing on the first column in table Table1 which is mentioned above.
Column datatype is int and the the value I am passing is 4.



I have tried that now and it worked for me (SQL 2012)

try re-creating the csv file?
Go to Top of Page

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 02/26/2013 :  16:32:12  Show Profile  Reply with Quote
quote:
Originally posted by dolphin123

It is matching.

It is failing on the first column in table Table1 which is mentioned above.
Column datatype is int and the the value I am passing is 4.



Try using FLOAT
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000