Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
a691u23
Starting Member
3 Posts |
Posted - 2003-03-20 : 11:27:15
|
| I have a delimited text file that I am importing into SQL Server via a bulk insert. The field separator is a comma and the opening and closing delimiters are double quotes. The data looks like this:"MRS","JESSICA","","NELSON","1 BEEKMAN PL","","AGAWAM","MA","01001"I am using a format file like this:7.091 SQLCHAR 0 3 "\",\"" 1 title2 SQLCHAR 0 15 "\",\"" 2 firstname3 SQLCHAR 0 1 "\",\"" 3 middleinitial4 SQLCHAR 0 21 "\",\"" 4 lastname5 SQLCHAR 0 40 "\",\"" 5 address16 SQLCHAR 0 40 "\",\"" 6 address27 SQLCHAR 0 20 "\",\"" 7 city8 SQLCHAR 0 2 "\",\"" 8 state9 SQLCHAR 0 5 "\r\n" 9 zipI am having problems with the title and the zip fields. The title data appears as "Mrs instead of Mrs . The zip data appears as "01001".I know the problem lies in the format file but I can't figure out how to fix it.Thanks in advance. |
|
|
samsekar
Constraint Violating Yak Guru
437 Posts |
Posted - 2003-03-21 : 04:58:28
|
| BOL Says..Using Format files,Note: It is possible to skip importing a table column if the field does not exist in the data file by specifying 0 prefix length, 0 length, 0 server column order, and no terminator. This effectively states that the data field does not exist in the data file, and that the server column should not have data loaded into it.format file.7.0101 SQLCHAR 0 0 "\"" 0 xxx2 SQLCHAR 0 3 "\",\"" 1 title3 SQLCHAR 0 15 "\",\"" 2 firstname4 SQLCHAR 0 1 "\",\"" 3 middleinitial5 SQLCHAR 0 21 "\",\"" 4 lastname6 SQLCHAR 0 40 "\",\"" 5 address17 SQLCHAR 0 40 "\",\"" 6 address28 SQLCHAR 0 20 "\",\"" 7 city9 SQLCHAR 0 2 "\",\"" 8 state10 SQLCHAR 0 5 "\"\r\n" 9 zipcreate table Prod (title varchar(5), firstname varchar(20), middleinitial varchar(3), lastname varchar(25), address1 varchar(50), address2 varchar(50), city varchar(25), state varchar(5), zip varchar(10))GOBULK INSERT Prod FROM 'C:\data.txt' WITH (FORMATFILE = 'c:\format1.txt')GOSelect * from ProdGODrop table prodEDIT: Change in format file at first and last file field order (1&10)Sekar~~~~Success is not a destination that you ever reach. Success is the quality of your journey.Edited by - samsekar on 03/21/2003 05:02:13 |
 |
|
|
|
|
|
|
|