Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Microsoft SQL Server: Programming FAQ

T-SQL Hints and Tips

How to use the BULK INSERT with a file that has double quotes
Posted: 7 Mar 02

You have to setup a format file to process a text file that has quotes around every field.  Here are the details:

this is two lines from a sample text file:
"1","2","3","4","5","6","7","8"
"22","23","33","44","45","56","57","58"

There are 8 fields to process.  Here is how the BULK INSERT would look:

bulk insert SALESTemp
    from '\\sales\sales.txt'
    with
        (
            formatfile='\\sales\sales.fmt'
        )

The fmt format file is coded as follows:

8.0
17
1       SQLCHAR       0       0       "\""                      0     dummy1             ""
2       SQLCHAR       0       50      "\""                      1     Field1             ""
3       SQLCHAR       0       0       ",\""                     0     dummy2             ""
4       SQLCHAR       0       50      "\""                      2     Field2             ""
5       SQLCHAR       0       0       ",\""                     0     dummy3             ""
6       SQLCHAR       0       50      "\""                      3     Field3             ""
7       SQLCHAR       0       0       ",\""                     0     dummy4             ""
8       SQLCHAR       0       50      "\""                      4     Field4             ""
9       SQLCHAR       0       0       ",\""                     0     dummy5             ""
10      SQLCHAR       0       50      "\""                      5     Field5             ""
11      SQLCHAR       0       0       ",\""                     0     dummy6             ""
12      SQLCHAR       0       50      "\""                      6     Field6             ""
13      SQLCHAR       0       0       ",\""                     0     dummy7             ""
14      SQLCHAR       0       50      "\""                      7     Field7             ""
15      SQLCHAR       0       0       ",\""                     0     dummy8             ""
16      SQLCHAR       0       50      "\""                      8     Field8             ""
17      SQLCHAR       0       0       "\r\n"                    0     dummy9             ""

The format file basically tells the bulk insert to ignore the double quotes.  The "FIELDx" are the names of the fields on the database.  This works great!

Back to Microsoft SQL Server: Programming FAQ Index
Back to Microsoft SQL Server: Programming Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close