Solved

BULK INSERT and bcp

Posted on 2001-06-14
7
512 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 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

25 Experts available now in Live!

Get 1:1 Help Now