Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Bulk Insert

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-04-12 : 23:01:41
I am in attempting to import data to a table that already exists. Here is what I have tried thus far:

create proc importcsvfile
(C:\Users\John & Tanya\Documents\John\Hospital Compare\Hospital_flatfiles\dbo_vwHQI_FTNT)
AS

begin

BULK INSERT dbo.HQI_FTNT
FROM dbo_vwHQI_FTNT WITH
(
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’

but am getting this error:

Msg 102, Level 15, State 1, Procedure importcsvfile, Line 3
Incorrect syntax near 'C:'.
Msg 102, Level 15, State 1, Procedure importcsvfile, Line 11
Incorrect syntax near '‘'.

Can you please help me with this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-13 : 03:11:25
quote:
Originally posted by jcb267

I am in attempting to import data to a table that already exists. Here is what I have tried thus far:

create proc importcsvfile
(C:\Users\John & Tanya\Documents\John\Hospital Compare\Hospital_flatfiles\dbo_vwHQI_FTNT)
AS

begin

BULK INSERT dbo.HQI_FTNT
FROM dbo_vwHQI_FTNT WITH
(
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’

but am getting this error:

Msg 102, Level 15, State 1, Procedure importcsvfile, Line 3
Incorrect syntax near 'C:'.
Msg 102, Level 15, State 1, Procedure importcsvfile, Line 11
Incorrect syntax near '‘'.

Can you please help me with this?


Post the full query

It should be something like

create proc importcsvfile
(
@file_name varchar(200)
)
AS

begin

BULK INSERT dbo.HQI_FTNT
FROM @file_name WITH
(
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’
)
.
.
.


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-13 : 03:13:21
It is the duplication of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=123675

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Rajesh Jonnalagadda
Starting Member

45 Posts

Posted - 2009-04-13 : 05:53:51
Hi,
Try this,

--STEP 1

CREATE PROCEDURE ImportCSVFile
AS
BEGIN
DECLARE @FileName NVARCHAR (100)
,@FilePath NVARCHAR (250)
,@Command NVARCHAR(500)

SET @FileName = 'FileName.csv'
SET @FilePath = 'C:\Users\John & Tanya\Documents\John\Hospital Compare\Hospital_flatfiles\dbo_vwHQI_FTNT\'

SET @Command = 'BULK INSERT TableName FROM "'+@FilePath + @FileName + '" WITH(ROWTERMINATOR =''\n'', FIELDTERMINATOR='','')'
EXEC (@Command)
END

--STEP 2

EXEC ImportCSVFile

Rajesh Jonnalagadda
[url="http://www.ggktech.com
"]GGK TECH[/url]
Go to Top of Page
   

- Advertisement -