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
 General SQL Server Forums
 New to SQL Server Programming
 SQL bcp tool

Author  Topic 

my2003
Starting Member

2 Posts

Posted - 2007-10-18 : 11:03:06
Hi,

I am using bcp to copy some data from a flat file to a data table using the format file that look like this.

9.0
7
1 SQLCHAR 0 4 "" 1 Col1 SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 9 "" 2 Col2 SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 8 "" 3 Col3 ""
4 SQLCHAR 0 7 "\n" 4 Col4 SQL_Latin1_General_CP1_CI_AS

There are 4 columns in total, however some rows have missing values for Column 4, and but given there are no field separators (all columns have fixed width and data is truncated if needed), how should the format be written to define a row terminator to apply to Column 3 if Column 4 is null.

Thanks for your suggestions.

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-18 : 11:32:01
What do you mean the column is null?

In a fixed width file it would be spaces



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

my2003
Starting Member

2 Posts

Posted - 2007-10-18 : 12:13:14
Hi Brett,

A sample data file that I am using is:

EA MESSAGE0019010101C2B711
EA MESSAGE0019010101
EA MESSAGE0019010101M053519

In this case the the 1st row and 3rd row both have values C2B711 and M053519 for Col 4, but the the 2nd one doesn't. There's no spaces that follow even though Col 4 defines a fixed width of 7.
This produces an error and prevents its from being copied. How can I make sure it gets copied into the data table with a null for this empty field?

Thanks,

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-18 : 15:49:04
What produces the file?

Maybe that proces needs to be corrected

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -