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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bulk Insert Multiple Text Files - blank space delimiter and tab-delimited - Error Received 1

Status
Not open for further replies.

BxWill

MIS
Mar 30, 2009
367
0
16
US
Bulk inserting multiple text files to create Lookup tables in a database using Sql Server 2012 Developer.

Able to successfully load one set of lookup tables, the ones with a blank space delimiter.

However, I encounter an error when I attempt to load the second set of text files that contain a tab delimited delimiter.

Specifically, it appears that the red error lines appear underneath the line "FIELDTERMINATOR = ' \t'"

with the error message "Incorrect syntax."


Is it recommended or even good practice to use bulk import to load multiple text files with different field delimiters using the same sql script?

Any insight as to how the example sql script below should be formatted so that the error is eliminated?


Code:
CREATE TABLE LU_Equipment(Data VARCHAR (50),MoreData varchar(50))
BULK INSERT LU_Equipment FROM 'c:\Equipment.txt'
           WITH ( 
               FIELDTERMINATOR = "   ", 
               ROWTERMINATOR = '\n', 
               FIRSTROW = 2 
            ) 


CREATE TABLE LU_Supplies(Data VARCHAR (50),MoreData varchar(50))
BULK INSERT BULKACT FROM 'c:\Supplies.txt'
           WITH ( 
               FIELDTERMINATOR = ' \t', 
               ROWTERMINATOR = '\n', 
               FIRSTROW = 2 
            )
 
Hi, not sure about the error where you are saying it's occurring, however you have double quotes on the FIELDTERMINATOR = " ", which would cause an issue.

G

There are two ways to write error-free programs; only the third one works.
 
GHolden, I think you've caught at least ONE of the OP's issues, if not THE issue. I should've seen it when I first glanced. I've been watching just b/c was interested in the general concept.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
kjv1611, thanks, not addressing the question as such, however as you're interested in the concept, I'd use SSIS or some other option rather than BULK INSERT, unless it was a one-off import. And in that case I'd just use the basic data import.

G

There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top