473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

BCP and treatment of NULLs when export to fixed format text file

We are using the bcp utility (via APIs) to export data from a SQL table
in a fixed format text file. BCP is inserting spaces for a field if
the field contains a NULL. This is fine with us except at the end of
the line, there are no spaces for that field just the end-of-row
terminator prematurely, so it looks like that field is not present and
messes up another piece of software we pump the text file into down
stream.

Example -- The last row illustrates the problem.

123-49-890 Mary Smith Raleigh NC \r\n
999-88-123 Henry Ax Boston MA \r\n
456-99-123 Sue Kite WA \r\n
789-88-126 Andy Yates Philadelphia \r\n

We have thought about using a SQL query to convert the NULL data
explicitly to spaces, but were wondering is there a switch or something
in our format file to get around this.

Thanks.

Jul 23 '05 #1
2 5609
On 2/8/05 2:40 PM, in article
11**********************@c13g2000cwb.googlegroups. com,
"ez******@hotmail.com" <ez******@hotmail.com> wrote:
We are using the bcp utility (via APIs) to export data from a SQL table
in a fixed format text file. BCP is inserting spaces for a field if
the field contains a NULL. This is fine with us except at the end of
the line, there are no spaces for that field just the end-of-row
terminator prematurely, so it looks like that field is not present and
messes up another piece of software we pump the text file into down
stream.

Example -- The last row illustrates the problem.

123-49-890 Mary Smith Raleigh NC \r\n
999-88-123 Henry Ax Boston MA \r\n
456-99-123 Sue Kite WA \r\n
789-88-126 Andy Yates Philadelphia \r\n

We have thought about using a SQL query to convert the NULL data
explicitly to spaces, but were wondering is there a switch or something
in our format file to get around this.

Thanks.


You could also assume that the bcp utility is skipping the NULL field
altogether and the \r\n represents the end of the record. I say this because
what you should see if what you are describing is true would be 2 sets of
\r\n...

123-49-890 Mary Smith Raleigh NC \r\n
999-88-123 Henry Ax Boston MA \r\n
456-99-123 Sue Kite WA \r\n
789-88-126 Andy Yates Philadelphia \r\n\r\n

I recommend looking at the data in a hex editor and see if that is the case.

-Greg

Jul 23 '05 #2
(ez******@hotmail.com) writes:
We are using the bcp utility (via APIs) to export data from a SQL table
in a fixed format text file. BCP is inserting spaces for a field if
the field contains a NULL. This is fine with us except at the end of
the line, there are no spaces for that field just the end-of-row
terminator prematurely, so it looks like that field is not present and
messes up another piece of software we pump the text file into down
stream.

Example -- The last row illustrates the problem.

123-49-890 Mary Smith Raleigh NC \r\n
999-88-123 Henry Ax Boston MA \r\n
456-99-123 Sue Kite WA \r\n
789-88-126 Andy Yates Philadelphia \r\n

We have thought about using a SQL query to convert the NULL data
explicitly to spaces, but were wondering is there a switch or something
in our format file to get around this.


I did this:

CREATE TABLE nullatend (a int NOT NULL,
b varchar(23) NOT NULL,
c char(4) NULL,
d char(2) NULL)
go
INSERT nullatend(a, b, c,d) values (1, 'kjkjl', NULL, 'KA')
INSERT nullatend(a, b, c,d) values (2, 'kjkjl', 'LKL', NULL)
INSERT nullatend(a, b, c,d) values (3, 'kjkjl', 'NULL', 'KA')

And then:

bcp tempdb..nullatend out slask.bcp -c -T

Looking at the out file in an editor that can show tabs, there appears to be
a final tab on line two, although that column has a NULL value.

Now, you only said "fixed format", but did not specify whether you are
using format files, delimiters etc. If it is not that simple that you
don't see the tab, it would help if you posted more details how you use
BCP. Best would be with a repro that populated a table with a few rows
and the issued a BCP command.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Neil | last post by:
Hi guyz, just trying out this google feature so if i post if in the wrong area i appologize. now to my question. BTW i'm new to access programming, i've done a little vb6.0 and vb.net but access...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
3
by: Daniel Wetzler | last post by:
Dear MSSQL- experts, I have a strange problem with SQLSERVER 2000. I tried to export a table of about 40000 lines into a text file using the Enterprise manager export assitant. I was astonished...
1
by: Billy | last post by:
Hi All, I'm attempting to use the MapNetworkDrive <snippedbelow from entire code below with very poor performance results. Basically, I have very small 73kb text files that are rewritten daily...
6
by: Cliff72 | last post by:
I need to fill in the nulls in the batch field the value from the record immediately preceding the null one ie replace the nulls with the preceding value until I hit a record with a value in...
4
by: janssensglb | last post by:
I want to export from Access 2000 a numeric field (double) to a text file. The export file should be fixed length (no delimiters), the field should have 9 digits in total, including 2 decimals. I...
5
by: BXB | last post by:
I have a number in a table that starts off as currency. There are nulls in the data so I'm trying to convert the nulls to zeros and then wind up back in currency, or in fact in any numeric format. ...
10
by: sara | last post by:
Hi - I have a report that is 14 columnar sub-reports (Line up: Position- holders in each of our 14 locations - Manager, Assistant Manager, Receiving, Office, etc). I output directly to PDF...
8
by: jcgads | last post by:
In ACCESS 2007 I need the results of a report in a fixed format file format text file. The record length of the file is 80 characters. The first record is a header record. It has the format of ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.