all groups > sql server dts > april 2007 >
You're in the

sql server dts

group:

How to export from SQL Server to multi-record text file


How to export from SQL Server to multi-record text file Woodberg
4/26/2007 3:49:45 PM
sql server dts:
I've got a project to export data from a SQL Server and get it into a text
file which has multiple records. Basically, the output file has a 3
records; a file record, a header record and a detail record. It has to be
configured like below:

File Record
Header 1
Detail 1
Detail 2
Detail 3
Header 2
Detail 1
Detail 2
Header 3
Detail 1

etc.

What is the best technique for doing something like this. I wanted to use
DTS to help automate the process.
Re: How to export from SQL Server to multi-record text file Allan Mitchell
4/30/2007 8:23:58 PM
Hello Woodberg,


Throw the different parts of the process to different files and then use
the COPY statement on the command line (Execute Process task) to bring them
together in one file. Make sure you specify the output files in the right
order when you join them back together again.



--

Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com

[quoted text, click to view]

Re: How to export from SQL Server to multi-record text file Woodberg
5/1/2007 11:42:42 PM
Thanks for the reply. One question though, with the COPY statement, can you
intersperse the different files into the final output file. I can't just
merge the different files one after another, I've got to keep the different
parts together. Is there a way to do that with the COPY command?


[quoted text, click to view]
Re: How to export from SQL Server to multi-record text file Allan Mitchell
5/2/2007 5:02:29 PM
Hello Woodberg,


COPY 1 + 2 + 3 4.txt will look like this in 4.txt

1
2
3

Is that what you require?



--

Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com

[quoted text, click to view]

Re: How to export from SQL Server to multi-record text file Woodberg
5/10/2007 4:14:31 PM
Actually, no that's not exactly right, if I'm understanding you correctly.
In your example. I would have 3 files and would combine them into 1 file.
However, all of the records from the first file would be together, followed
by the records from the second file and finally followed by the records in
the third file.

What I need to do is slightly different. Data I'm working with has to be
arranged in such a way that the 3 record layouts are mixed up in
header/detail format. I tried to explain this in my first note but must not
be doing a good job.

My output file needs to look like the following example:

Batch Record
Header Record 1
Detail Record 1
Detail Record 2
Detail Record 3
Header Record 2
Detail Record 4
Detail Record 5
Batch End Record

Hopefully that makes sense.

[quoted text, click to view]
Re: How to export from SQL Server to multi-record text file Allan Mitchell
5/11/2007 8:20:23 PM
Hello Woodberg,

aaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh why didn't
you say <grin>

OK. Personally I would use a Script Component as a destination and go against
a File connection manager to do the writing. This is the only way I can
see that you will get the flexibility you need.

--

Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com

[quoted text, click to view]

Re: How to export from SQL Server to multi-record text file Den
7/25/2007 5:52:25 PM
How about using a stored procedure to build a temprary table to put the data
in the order and structure you want. Then use a DTS package to take the
table data to a text file.


[quoted text, click to view]
AddThis Social Bookmark Button