Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 BCP from SQL to TXT file

Author  Topic 

justjohno
Starting Member

23 Posts

Posted - 2012-02-09 : 18:35:20
I'm using the BCP command below from within DOS to export a table (Encounter) into a text file, using a pipe as the delimiter. This has been working just fine until the character ":" was put into the table. BCP now uses this as the delimiter. When I run the command it will work fine until it gets to this character and skews the TXT file.

bcp MEDASSETS..Encounter out "f:\MedAssets\daily_file_Tran\ENC.txt" -T -c -t"|"

John O

justjohno
Starting Member

23 Posts

Posted - 2012-02-09 : 18:39:10
I don't need to use BCP, If there is another way to get this done please point me in that direction. I just need to get this into a "|" delimited file.

John O
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 18:44:08
you can use OPENROWSET also for this or even export import wizard

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

justjohno
Starting Member

23 Posts

Posted - 2012-02-09 : 18:47:32
Thanks for the reply, I've never used OPENROWSET. Let me check it out and see what I can do.

John O
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-02-09 : 21:33:01
are you sure there isn't a pipe in the file? a colon shouldn't break the format if pipe is the delimiter.

why not use a more unlikely delimiter?
Go to Top of Page

justjohno
Starting Member

23 Posts

Posted - 2012-02-10 : 11:52:19
I hate to sound so green, but looking into this further it appears to be return characters that's causing it skew and not the ":" delimiter. If I look at the result, it returns "BOX" Character. If I look at the front end the text is in several lines in a single field. Thanks for helping through this. I'm going create a script to search for the return and replace with space. Is there an easier way?

John O
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-10 : 11:59:47
quote:
Originally posted by justjohno

I hate to sound so green, but looking into this further it appears to be return characters that's causing it skew and not the ":" delimiter. If I look at the result, it returns "BOX" Character. If I look at the front end the text is in several lines in a single field. Thanks for helping through this. I'm going create a script to search for the return and replace with space. Is there an easier way?

John O


yep use
REPLACE(REPLACE(yourfield,CHAR(10),' '),CHAR(13),' ')

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

justjohno
Starting Member

23 Posts

Posted - 2012-02-10 : 15:36:21
Exactly visakh16, that's what took care of it.
Thanks everyone for the help. It now works.


John O
Go to Top of Page
   

- Advertisement -