BCP to create flat file
I'm trying to create a fixed length text file from a database table. I'm running a bcp command from the command line using a format file. The fixed length text file is getting created, but it's inserting extra spaces between
the columns. What I need is first name in columns 1-12, middle name in columns 13-24. It appears that what I'm getting is first name in columns 1-12, four spaces and middle name in columns 17-28.
How do I eliminate the spaces (maybe it's a tab?) between the columns?
May 3rd, 2011 8:15pm
Have you verified the length of the fields in your table? Also, how does the format file look like?For every expert, there is an equal and opposite expert. - Becker's Law
My blog
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2011 8:24pm
If there are trailing spaces on the columns , then rather use a query to trim the columns and dump it using bcp e.g !! bcp "select top 100 ltrim(rtrim(Column1)), ltrim(rtrim(column2)) from dbname.dbo.tablename" queryout "C:\XXX\XXX.txt" -c -T SridharSridhar
May 4th, 2011 2:05am
I have verified the field lengths.
9.0
2
1 SQLCHAR 0 12 "" 1 First_Name
SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 12 "\r\n" 2 Middle_name
SQL_Latin1_General_CP1_CI_AS
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2011 3:27pm