February 1, 2017 at 10:53 am
Does anyone know how I can import data from a csv file(pipe delimited) into a sql server database table using bcp client?
Any help will be appreciated,
Thanks.
February 1, 2017 at 11:21 am
The documentation on BCP is very good and BCP contains too many options for us to give you an intelligent response with so little information. I suggest that you Google bcp and try it, and then come back here if you run into problems.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
February 1, 2017 at 12:05 pm
Thank you Drew. Your comment helps me narrow my question.
I think the most difficult part is asking the right question. Hopefully I do to get the answer I'm looking for.
What is the bcp command I need to generate the format file for importing a pipe delimited data?
Thanks in advance.
February 1, 2017 at 12:10 pm
The documentation has an example on how to create a format file. You'll also need to use the -t option to change the delimiter to a pipe (from the default tab).
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
February 1, 2017 at 12:14 pm
Got it. The documentation the Sqlservercentral.com. Thanks so much. I will look at it now and post any question I may have. Thanks again.
February 1, 2017 at 12:18 pm
If it's not too much to ask, do you mind dropping the link to the documentation here? I'm trying to navigate my way to where the documentation is, but I'm not sure. Thanks in advance.
February 1, 2017 at 12:27 pm
Not to worry; I think I found the information i'm looking for. Thank you!
February 2, 2017 at 6:18 am
You might want to take a look at this article.
http://www.sqlservercentral.com/articles/BCP+(Bulk+Copy+Program)/105867/
February 3, 2017 at 12:43 pm
So, I was able to create my format file successfully. However, when I test the process of extracting data from a table using the format file I get the following error:
SQLState = HY000, NativeError = 0
Error = [Microsoft][SQL Native Client]Unable to open BCP host data-file
Any help with this will be highly appreciated....
February 3, 2017 at 12:47 pm
smatu - Friday, February 3, 2017 12:43 PMSo, I was able to create my format file successfully. However, when I test the process of extracting data from a table using the format file I get the following error:SQLState = HY000, NativeError = 0
Error = [Microsoft][SQL Native Client]Unable to open BCP host data-fileAny help with this will be highly appreciated....
Does SQL Server has access to the file? Are you using a path according to the server and not the local machine?
February 3, 2017 at 12:55 pm
I'm not sure I understand your question....
February 3, 2017 at 3:30 pm
smatu - Friday, February 3, 2017 12:55 PMI'm not sure I understand your question....
How are you calling bcp?
February 3, 2017 at 3:56 pm
We've been guessing long enough. Please post your unadulterated BCP command with the obvious exception of obfuscating ServerName, Login, and Password. Also, for imports, BCP may be the wrong tool. It may well be better to use BULK INSERT but depends on where the file being imported actually is. And you likely DON'T need a BCP Format file for either of these because you can specify the column separator in the code.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 3, 2017 at 9:30 pm
Jeff Moden - Friday, February 3, 2017 3:56 PMWe've been guessing long enough. Please post your unadulterated BCP command with the obvious exception of obfuscating ServerName, Login, and Password. Also, for imports, BCP may be the wrong tool. It may well be better to use BULK INSERT but depends on where the file being imported actually is. And you likely DON'T need a BCP Format file for either of these because you can specify the column separator in the code.
I agree.
Whenever working with CSV files and file formats, I have always found OPENROWSET BULK much more reliable and much more flexible.
https://msdn.microsoft.com/en-us/library/ms190312.aspx
February 4, 2017 at 11:38 am
phil.doensen - Friday, February 3, 2017 9:30 PMJeff Moden - Friday, February 3, 2017 3:56 PMWe've been guessing long enough. Please post your unadulterated BCP command with the obvious exception of obfuscating ServerName, Login, and Password. Also, for imports, BCP may be the wrong tool. It may well be better to use BULK INSERT but depends on where the file being imported actually is. And you likely DON'T need a BCP Format file for either of these because you can specify the column separator in the code.
I agree.
Whenever working with CSV files and file formats, I have always found OPENROWSET BULK much more reliable and much more flexible.
https://msdn.microsoft.com/en-us/library/ms190312.aspx
I'll have to disagree in the reliability thing when it comes to OPENROWSET vs BULK INSERT vs BCP. All 3 are extremely reliable and flexible depending on what you're using them for and how you're using them.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply