SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


BULK INSERT & Text Qualifier


BULK INSERT & Text Qualifier

Author
Message
mwosinski
mwosinski
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 3
And what if my data looks like this:

datahere,"data with a comma, more",xxx
datahere,data without a comma,xxx
Sergiy
Sergiy
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24831 Visits: 12464
All of you are wrong.
Using "," as delimites is an error waiting to happen.

mdjtlj, ask you supplier to build a test file containing '19" Monitor'.
Then try to process that file.
Sergiy
Sergiy
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24831 Visits: 12464
For this kind of files it's better to use ODBC drivers.
They read those strings with identifiers properly.

I created text file TestInsert.txt in the folder C:\TextFiles (local to the SQL Server instance):
"Name","Price"
"Test","1,1"
"19""Monitor, the nice one","250"



Then I added linked server:
EXEC sp_addlinkedserver txtsrv1, 'Jet 4.0', 
'Microsoft.Jet.OLEDB.4.0',
'C:\TextFiles',
NULL,
'Text'



To see the list of files available:
EXEC sp_tables_ex txtsrv1



And now - just simple SELECT:
SELECT * 
FROM txtsrv1...[TestInsert#txt]



I remember this code was done based on BOL examples, but I don't remember the topic.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)

Group: General Forum Members
Points: 208407 Visits: 41973
Sergiy (1/14/2008)
All of you are wrong.
Using "," as delimites is an error waiting to happen.

mdjtlj, ask you supplier to build a test file containing '19" Monitor'.
Then try to process that file.


Works fine if BCP format file is properly constructed. Delimiter of "," (including the quotes) is perfect for "real" CSV instead of "comedy separated values".

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)

Group: General Forum Members
Points: 208407 Visits: 41973
remember this code was done based on BOL examples, but I don't remember the topic.


First, nice idea... hadn't thought about doing it that way. Great way to import from a staging area. Thanks for the tip.

And the topic you're looking for is "Linked Servers".

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Sergiy
Sergiy
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24831 Visits: 12464
Jeff Moden (1/18/2008)
[quote]Delimiter of "," (including the quotes) is perfect for "real" CSV instead of "comedy separated values".

Delimiter of "," is as good as '[' + @TableName + ']'.
Works almost every time.
But it's better to use QUOTENAME. Because it deals properly with quotes inside of the variable.
prabu_onnet
prabu_onnet
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 2
Dear All,

I am also faced the same problem mentioned above, using CSV file bulk upload with [ " ] as a Text Qualifier. Any one have a solution.

I am waiting......

Thanks
Prabu
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)

Group: General Forum Members
Points: 208407 Visits: 41973
Ummm... the answer is actually near the beginning of this thread. Instead of waiting, read the rest of the thread.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Richard Hurst-243142
Richard Hurst-243142
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 43
Alternatively you could just do a find and replace on the original file and get rid of them that way.

I just did because the whole thing was driving me towards an even deeper insanity
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)SSC Guru (208K reputation)

Group: General Forum Members
Points: 208407 Visits: 41973
Richard Hurst (3/10/2009)
Alternatively you could just do a find and replace on the original file and get rid of them that way.

I just did because the whole thing was driving me towards an even deeper insanity



Using which tool, Richard?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search