Re: Maintaining Field Length in .txt format

From: Steve Kass (skass_at_drew.edu)
Date: 11/16/04


Date: Tue, 16 Nov 2004 17:58:02 -0500

How are you exporting the data now? If you export the data with bcp,
and the column types are CHAR, not VARCHAR, they will be padded with
spaces as you want. If the types are VARCHAR, then export a query that
converts them to CHAR types.

As for appending, I don't think there's a way to do it, but you can
create two text files and append them with a shell command, called from
SQL Server or not (exec master..xp_cmdshell 'COPY a.txt/A+b.txt/A
c.txt/A' from SQL Server).

Steve Kass
Drew University

J. Joshi wrote:

>Hello all,
>
>I have run into something very bizzare and something I
>have not come accross before. We have a data feed that
>goes into a legacy mainframe system (not sure which
>platform) every month. Unfortunately or fortunately, we
>are on a SQL Server 2000 environment and I can create
>a .txt file with 7 required fields.
>
>Here's the problem: The ending position of each field is
>very specific. E.g. LastName field starts @ col.19 & ends
>@ Col43 or 25 characters long (CHAR datatype). How do I
>fill in the gaps with a blank space with the Lastname is
>not 25 characters long? And so on for other fields? That
>to in a .txt file format?
>
>Also - is there any way to append data to an existing .txt
>file using SQL? The header information for the feed to be
>sent creats a .txt file. Then I have to feed in the data-
>set in teh same .txt file using another sproc. The header
>field length is completely diff than the data-set field
>length. This is very old school but such is the nature of
>the project!
>Any ideas on this?
>
>Joshi
>
>



Relevant Pages

  • Re: returning @@RowCount
    ... use VARCHAR. ... CHAR will pad the data with spaces ... SQL Server MVP ... >> alter procedure stp_Family ...
    (microsoft.public.sqlserver.programming)
  • Re: Loading a variable
    ... Sorry I want the variable to be char or varchar so that I ... >> Let's say I have a simple three column table, temp27, ... >> with a couple of rows in sql server 2000. ...
    (microsoft.public.sqlserver.server)
  • Re: Data types
    ... If the data is variably sized, use varchar. ... Programming with fixed length char value is a pain. ... Pro SQL Server 2000 Database Design - ...
    (microsoft.public.sqlserver.programming)
  • RE: Loading a variable
    ... Sorry I want the variable to be char or varchar so that I ... >> Let's say I have a simple three column table, temp27, ... >> with a couple of rows in sql server 2000. ...
    (microsoft.public.sqlserver.server)
  • Re: Conversion error
    ... You canimport both types of data into a varchar column now. ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) ... www.SQLDTS.com - The site for all your DTS needs. ... >>character data has to be one or the other. ...
    (microsoft.public.sqlserver.dts)