BCP upload from a txt file

  • Sergiy - Tuesday, August 8, 2017 5:39 AM

    Check your field terminators.Field 2 in the example above has a terminator "/r" - is it how it is in the actual file?"/r" would be expected for the last column, not the 2nd one.

    Sorry Sergiy that's my fault, I posted and edited portion of my test file and cocked it up :blush:

    Far away is close at hand in the images of elsewhere.
    Anon.

  • This is weird. I'm not seeing the text file anywhere in this thread. I thought maybe the OP sent it to you via PM, David, but after the last few replies, I'm sure that's not the case.

    Which post in this thread has the file attached?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin - Tuesday, August 8, 2017 6:14 AM

    This is weird. I'm not seeing the text file anywhere in this thread. I thought maybe the OP sent it to you via PM, David, but after the last few replies, I'm sure that's not the case.

    Which post in this thread has the file attached?

    No, the only information available is the sample portion the OP posted.
    I took them at their word that the format file has 24 lines and has "\t" as the row terminator except the last which was "\r\n".

    Far away is close at hand in the images of elsewhere.
    Anon.

  • This is what failing to help us help you looks like.  Without seeing the query, the format file, and the data file (with sample data, not live data) all you are going to get are shots in the dark.

  • sqlenthu 89358 - Friday, August 4, 2017 7:21 AM

    Hi Guys,
    I an trying to do a simple upload from a txt file to a table. I know it should be a simple bcp command but if i have to load with a where clause how can we do it. Take any small text file as an example.

    If you need a WHERE clause during your initial load from the file to a "table", then you're probably trying to load the file directly into the final destination table, which I normally consider to be a bad idea for multiple reasons.  My recommendation would be to always load to a staging table rather than the final table so that you can do some high performance data validation and/or cleansing prior to sending the data to it's final destination.

    The error you reported has to do with the format file.  You provided a part of it and made a mistake in posting it.  Stop trying to paraphrase your problem.  Post the actual format file as it is in your environment.

    Also, your OPENROWSET command has an error in it.  "Format File" should not be two words.  It should be one.  I suspect that you're having the same "paraphrasing" problem there.  Stop messing around with all that and post the actual code that you have.

    Last but not least, your format file identifies the incoming data as SQLNCHAR.  Are all of the columns in the file actually Unicode?  And what code page does the file actually use?  If it's a UTF-8 file, you'll need to find a way to do some preprocessing because UTF-8 isn't supported in SQL Server for imports or exports until SQL Server 2016.

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

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sorry for the late update everyone. Had not been a good time for me health wise. I was able to figure out what was the issue. One of the column in for mat file had SQLFLT8 with length of just 2. I changed it to 10 and it worked fine.

    Once again apologies for replying late on this.

  • sqlenthu 89358 - Monday, August 14, 2017 10:43 AM

    Sorry for the late update everyone. Had not been a good time for me health wise. I was able to figure out what was the issue. One of the column in for mat file had SQLFLT8 with length of just 2. I changed it to 10 and it worked fine.

    Once again apologies for replying late on this.

    Glad you figured it out. Thanks for posting the details and solution.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 7 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply