Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BULK INSERT question

Status
Not open for further replies.

cmhunt

Programmer
Apr 17, 2001
119
GB
Hi

I have a standard CSV file which has double quote enclosed fields. How do I specify in BULK INSERT that fields are quote enclosed. Currently
Code:
BULK INSERT #TestTable FROM 'F:\*****\Production\Test Files\file.csv'
WITH (
	FIELDTERMINATOR = ',',
	ROWTERMINATOR = '\n'
)
works fine but leaves the quotes in.

Any help would be gratefully appreciated.

Thanks

Chris
 
I could not find a way to do this, and had to revert to making the CSV file without quotation marks as text identifiers...

*cLFlaVA
----------------------------
Breaking the habit...
 
Can't believe it's the easiest way to do it but this drops the first and last character off every field in the table:
Code:
DECLARE @MaxFields AS int,@FieldCounter AS int, @TableID AS int, @SQL AS varchar(4000), @FieldName AS varchar(4000)
SET @FieldCounter=1
SET @MaxFields=(SELECT MAX(colid) FROM syscolumns WHERE id=(SELECT id FROM sysobjects WHERE name='TestTable')) + 1
SET @TableID=(SELECT id FROM sysobjects WHERE name='TestTable')
WHILE @FieldCounter < @MaxFields
	BEGIN
		SET @FieldName=(SELECT Name FROM syscolumns WHERE id=@TableID AND colid = @FieldCounter)
		SET @SQL = 'UPDATE TestTable SET ' + @FieldName + ' = SUBSTRING(' + @FieldName + ',2,LEN(' + @FieldName + ')-2)'
		EXECUTE(@sql)
		SET @FieldCounter = @FieldCounter + 1
	END

Anyone know if I can do this with a temp table??

Thanks

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top