Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BULK INSERT and bcp

Posted on 2001-06-14
7
Medium Priority
?
530 Views
Last Modified: 2012-06-27
Is there any way to get BULK INSERT (or bcp) to ignore quotes enclosing character data in an comma-delimited ASCII text file?
My preferred method for this import is to use a bcp format file but I find that the quotes are always imported along with the data.
Thanks
0
Comment
Question by:sduckett
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:amitpagarwal
ID: 6190226
i would suggest that after exporting the data (with quotes) into a flat file, you could manipulate the text file to remove the quotes or substitute them with some another character.

if u have sed, just say
cat BCPFILE | sed 's/\"//g' > NEWFILE

or open the file in vi and goto escape mode, say 1,$ s/\"//g

Else u can even create a view on that table where the data in the view is without quotes and u could actually bcp out that view.

Thanks.

0
 
LVL 3

Author Comment

by:sduckett
ID: 6190250
amitpagarwal, thanks for your comments.
I am really looking to find out if bcp can be instructed to ignore the quotes.
The file (flat text) I must import, on a regular basis, is ENORMOUS (>15Gb, containing every address in the UK) so I would like to avoid any pre or post processing.
I was wondering if there is anything clever that can be done with the bcp format file (or some other method) to manage this common file format("character data","more data",0.59,"data").
0
 
LVL 5

Expert Comment

by:amitpagarwal
ID: 6190261
oh the file is really huge...
i can't think of anything apart from post formatting using sed ..

anyway, thanks.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 3

Author Comment

by:sduckett
ID: 6190268
No, Thank YOU
0
 
LVL 3

Author Comment

by:sduckett
ID: 6190368
I found the following example:
It is exactly what I was looking, so I have effectively answered my own question. I am posting the solution here for future reference.

amit, Does a 'B' grade sound fair?

For the data file:

"XX",20,"CC"
"TT",30,"RD"

When the second column is type integer, the remaining columns have a character data type, and the data is in quotation marks for the character data type. Use the following BCP-format file:

4.2
7
1     SYBCHAR       0       0       "\""     0      dummy1
2     SYBCHAR       0       2       "\""     1      col1
3     SYBCHAR       0       0       ","      0      dummy2
4     SYBCHAR       0       2       ","      2      col2
5     SYBCHAR       0       0       "\""     0      dummy3
6     SYBCHAR       0       2       "\""     3      col3
7     SYBCHAR       0       0       "\r\n"   0      dummy4

0
 
LVL 5

Accepted Solution

by:
amitpagarwal earned 600 total points
ID: 6190394
Thanks sduckett, the format file is a nice idea .. wish i could think that far ..

Amit.
0
 

Expert Comment

by:viperguynaz
ID: 7350467
This helped me solve a problem...but here's an easier solution...

8.0
3
1     SQLCHAR       0       2       ","      1      col1 RAW
2     SYBCHAR       0       2       ","      2      col2 RAW
3     SQLCHAR       0       0       "\r\n"   3      col3 SQL_Latin1_General_CP1_CI_AS
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question