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.
| 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)ASbeginBULK INSERT dbo.HQI_FTNTFROM dbo_vwHQI_FTNT WITH(FIELDTERMINATOR = ‘,’,ROWTERMINATOR = ‘\n’but am getting this error:Msg 102, Level 15, State 1, Procedure importcsvfile, Line 3Incorrect syntax near 'C:'.Msg 102, Level 15, State 1, Procedure importcsvfile, Line 11Incorrect 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)ASbeginBULK INSERT dbo.HQI_FTNTFROM dbo_vwHQI_FTNT WITH(FIELDTERMINATOR = ‘,’,ROWTERMINATOR = ‘\n’but am getting this error:Msg 102, Level 15, State 1, Procedure importcsvfile, Line 3Incorrect syntax near 'C:'.Msg 102, Level 15, State 1, Procedure importcsvfile, Line 11Incorrect syntax near '‘'.Can you please help me with this?
Post the full queryIt should be something likecreate proc importcsvfile(@file_name varchar(200))ASbeginBULK INSERT dbo.HQI_FTNTFROM @file_name WITH(FIELDTERMINATOR = ‘,’,ROWTERMINATOR = ‘\n’)...MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
Rajesh Jonnalagadda
Starting Member
45 Posts |
Posted - 2009-04-13 : 05:53:51
|
| Hi,Try this,--STEP 1CREATE PROCEDURE ImportCSVFileASBEGINDECLARE @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 2EXEC ImportCSVFileRajesh Jonnalagadda[url="http://www.ggktech.com"]GGK TECH[/url] |
 |
|
|
|
|
|
|
|