Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

BULK INSERT Different Data Types in the SAME Columns Expand / Collapse
Author
Message
Posted Tuesday, March 19, 2013 2:25 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 19, 2013 12:57 PM
Points: 17, Visits: 70
Issue: I have a small csv file uploaded through a web page by an end-user. It has two INT columns. Sometimes, the user accidentally uploads the column headers - they are varchar. I am using BULK INSERT to get the rows into a temporary table. The bulk insert works fine when the column headers are NOT there. It silently fails when the column headers are there. I specifically changed the table definition to use NVARCHAR's for the input when I discovered that the end-users were uploading the column headers.

SET @Command = N'CREATE TABLE ##temp_123 ([Staging_ID] NVARCHAR(512), [LeadID] NVARCHAR(512))'
EXECUTE sp_ExecuteSQL @Command

SET @Command = N'BULK INSERT ##temp_123 FROM ''' + @InputFileNameWithPath + N''' WITH ( FIELDTERMINATOR = '','', ROWTERMINATOR = '''')'
EXECUTE sp_ExecuteSQL @Command

I can see the temp table. When the input file has column headers, there is one row with both columns NULL. When there are no column headers, there are as many rows as in the user's file and they all have values.

I'm stumped. Thanks in advance.
- Seth
Post #1432897
Posted Wednesday, March 20, 2013 1:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 28, 2013 10:20 PM
Points: 45, Visits: 309
Should not be NULL as you have already used NVARCHAR.
What's the difference in the header row and the data row?Is that also comma separated?
Can you please send the sample input file.
Post #1433026
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse