0

What I'm doing is inserting into a table using bulk insert from a csv. There are fixed number of columns which I need to input.

Code:

BULK INSERT #TEMP FROM 'c:\temp.csv' 
WITH
(
  FIELDTERMINATOR = ','
, ROWTERMINATOR = '\n'
, CODEPAGE = 'RAW'
,FIRSTROW =2
)

Input:

A,B,C,D,E
A,B,C,D,E

Problem:

The column containing the values E are not to be written into the table because there is no column to store those values. When I take these values into the table, the last column is shown like this:

D,E
D,E

Question:

Is there any way to prevent the insertion of column E into the table without using a format file? I cannot use OPENROWSET to get these values as there are some permission issues.

Aashray
  • 2,753
  • 16
  • 22
  • I need the value `D` to be stored but the value `D,E` is being stored instead. I need to avoid that. – Aashray Oct 11 '13 at 08:53
  • You're using a temp table; can you add a column for e, then drop it after inserting? – ps2goat Oct 11 '13 at 08:53
  • There are a few answers to a similar question here: http://stackoverflow.com/questions/14711814/ignore-certain-columns-when-using-bulk-insert – ps2goat Oct 11 '13 at 08:55
  • The user enters values into the `csv` and then uploads it. After parsing the input, I'm getting the output. The `E` column shouldn't exist, but how do I determine if that is the wrong input or not? – Aashray Oct 11 '13 at 08:56
  • I already checked that question out. That's why I mentioned in my question `without using a format file`. And the number of invalid columns maybe more than one. – Aashray Oct 11 '13 at 08:58

1 Answers1

0

As others have mentioned, you cant ignore a field while doing bulk insert. If you don't have access to the format file, then import into your temp table, and drop the columns you don't need.

dubman23
  • 29
  • 4