Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Import CSV file

I would like to import a csv file into a table with a stored procedure.

Let's say that the file is located at
c:\foldername\web.csv

I want * inserted into tblWebs
Avatar of Sham Haque
Sham Haque
Flag of United Kingdom of Great Britain and Northern Ireland image

DECLARE @bulk_cmd varchar(1000)
SET @bulk_cmd = 'BULK INSERT tblWebs
FROM ''c:\foldername\web.csv''
WITH (FIELDTERMINATOR =' ,')
EXEC(@bulk_cmd)
assuming c: is the local drive of the database server
Avatar of Larry Brister

ASKER


gbshahaq:

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ','.
Msg 105, Level 15, State 1, Line 4
Unclosed quotation mark after the character string ')
EXEC(@bulk_cmd)
'.
that's a bit bad - copied that from BOL!!
try this:

DECLARE @bulk_cmd varchar(1000)
SET @bulk_cmd = 'BULK INSERT tblWebs
FROM ''c:\foldername\web.csv''
WITH (FIELDTERMINATOR ='' ,'')'
EXEC(@bulk_cmd)
ASKER CERTIFIED SOLUTION
Avatar of Sham Haque
Sham Haque
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gbshahaq:
  Thanks...don't know bout you but I'm not particular...just want to 'ger er done!

Points being awarded now