473,769 Members | 5,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5679
On 2/8/05 2:40 PM, in article
11************* *********@c13g2 00...legr oups.com,
"ez******@hotma il.com" <ez******@hotma il.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******@hotma il.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..nullate nd 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****@sommarsk og.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
14737
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 vba is a little confusing for me since i have never used it plus i have lost touch with vb coding since last 8 monhts. anywayz, my problem is i'm trying to export a table that's modified by me which is taken from a file at a prompt, now i have to...
12
2990
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 and not have it affected by the null? because it is right now causes truncated data at wierd places... but as soon as i manually with a hex editor change char(00) to char(20) in the files it reads prerfectly... which leads me to my 2nd...
3
3960
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 to get an exported text file of about 400 MB instead 16 MB which is the normal size of that data. By examining this file with a text editor I found that the file included alongside the data of my table MANY zeros which caused the big file size.
1
3898
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 to a network share using the MapNetworkDrive command to connect to the valid \\servername\share path. After successfully connecting the drive in the ASP code, the text file
6
5455
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 it--then hold the next value through the next set of nulls, and so on. See example below: I wanna copy down batch "IMR138" in record ID 1, all the way to ID 10. Then copy down batch "7138" all the way to ID 20 and so on....
4
2858
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 want the field to be right aligned so that the decimal separator is always in the same column in the text file. I don't want to fill any leading blanks with zeros. I tried to do this using the format function in a query but I always end up with...
5
2368
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. I've tried both of these. Add: Format(nz(,0),"Standard") Add: Format(nz(,0),"$#,##0.00") With this I wind up with what looks like numbers but when I export to Excel or try to subtotal at the bottom of the query I don't have numbers that...
10
2147
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 (using ConvertReportToPDF from this site - Stephan Lebans) The formatting - Outlines on some fields - do not appear on subreports
8
2982
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 ##SET14 space)today's date as a 8 digit date)a 6 character transaction count with leading zeros) i.e. ##SET HRF10132009000013 The data records have a format of X2(a 9 digit Id)(today's date as a 8 digit date)(5...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.