Solved

BULK INSERT and bcp

Posted on 2001-06-14
7
509 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 200 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now