• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

bcp to a text file

I need to convert a table to a text file(MSSQL 6.5) on fixed length format(no commas or tab terminators)
that is what i got so far:
bcp db.dbo.table1 out file.txt /c /Sdb /Usa /PPASSWORD> test.log
0
eliasis
Asked:
eliasis
1 Solution
 
Gandalf32Commented:
That command will create a tab delimited file. If you need a fixed file, then you need to create a format file (with the -f parameter). Simply do not include the /c parameter, and the bcp command will allow you to create the format file.
0
 
Gustavo Perez BuenrostroCommented:
You can specify /t and /r arguments of BCP utility to avoid field and row terminator in output file. Remember that the default values are (tab and newline character).

You can change the default field terminator to specify no terminator value using /t argument with no value (/t).

According to your code:

bcp db.dbo.table1 out file.txt /c /t /Sdb /Usa /PPASSWORD /otest.log
0
 
eliasisAuthor Commented:
I tried "/t argument with no value", but I get blank space between every field
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
eliasisAuthor Commented:
I tried "/t argument with no value", but I get blank space between every field
0
 
rayasamCommented:
If you want to use bcp to output to a text file as fixed length  use bcp format file. issue the sbove bcp command without a /c. Bcp will prompt you for the length and the column terminator. Do not provde a column terminator except for the last column.

Hop this helps!
0
 
simonsabinCommented:
You will need to use the /f to create a format file and then subsequently you can specify the format file you have just created.
0
 
Gustavo Perez BuenrostroCommented:
Try using 0 value for the field terminator and let me know haw it works for you:

bcp db.dbo.table1 out file.txt /c /t0 /Sdb /Usa /PPASSWORD /otest.log
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now