October 24, 2008 at 7:46 am
HI my name is Bhavin, and I want to insert the data from CSV file to
SQL Server 2005 Database. I am using SQL Bulk insert command. But I
have problem will adding the data to the databse
Here is the code
BULK
INSERT CSVTest
FROM 'c:\csvtest.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = ''
)
And the csvtest.csv files look like :
"A","B","C","D","E","F","G"
"10/01/2008 00:00","CAPITL",61757,51.83,2.61,0.00,"N"
"10/01/2008 00:00","CENTRL",61754,48.57,-0.64,0.00,"N"
..............................
..............................
and so on
The problem is Date and string character are in Quotes and Number are
without Quotes so I cannot used Comma separated values, and this is
the nature of the file and I want to make the process automated so I
would like if I can do some thing in SQL, rather then using some code
to replace the string. And also I want to delete the first line
i.e"A","B","C","D"...... because that is the column name
Please Help to solve the problem.
Thanks in Advance.
October 24, 2008 at 3:08 pm
another option may be to use OPENROWSET instead, with the Access driver. It's a bit more forgiving when dealing with quoted CSV files:
INSERT INTO CSVTest
SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Text;Database=C:\;','SELECT * FROM [csvtest.csv]')
October 28, 2008 at 9:16 am
Thank You very much Chris the above solution really help me,
Thanks a lot
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply