dbTalk Databases Forums  

Insert Title into text file during transformation task in DTS package

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Insert Title into text file during transformation task in DTS package in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ilin Start via SQLMonster.com
 
Posts: n/a

Default Insert Title into text file during transformation task in DTS package - 06-29-2005 , 01:57 PM






I have DTS package, which loads data from SQL Stored Proc into text file via
Transformation task.
How can I insert title as a first record in the text file?
Thanks,
Ilin

--
Message posted via http://www.sqlmonster.com

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS package - 06-29-2005 , 02:02 PM






The way 99% of people use is to export the title to a different file and
unite the data text file with the header file using COPY on the cmdline



--



Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
www.konesans.com - Consultancy from the people who know


"Ilin Start via SQLMonster.com" <forum (AT) SQLMonster (DOT) com> wrote

Quote:
I have DTS package, which loads data from SQL Stored Proc into text file
via
Transformation task.
How can I insert title as a first record in the text file?
Thanks,
Ilin

--
Message posted via http://www.sqlmonster.com



Reply With Quote
  #3  
Old   
Ilin Start via SQLMonster.com
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS package - 06-29-2005 , 03:56 PM



Thanks, but unfortunately I can not do this. It should be done inside of data
transformation task and should be run automatically on scheduler.
Any other idea?
Ilin

--
Message posted via http://www.sqlmonster.com

Reply With Quote
  #4  
Old   
frank chang
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-29-2005 , 05:25 PM



Ilin, I have done a similar thing that you want to do in a transformation
task for Excel files. As I understand it, you want to automatically insert a
title line at the beginning of the text file in the data transformation task.
First, one might change the data types of all the columns in your stored
procedure result set to varchar(nnn) using the convert function. Then one
might modify the stored procedure so that the first row in the result set it
returns contains your desired title mapped to the fields in your text file
using UNION and appropriate sort orders in your stored procedure. The
results may not look picture perfect.

"Ilin Start via SQLMonster.com" wrote:

Quote:
Thanks, but unfortunately I can not do this. It should be done inside of data
transformation task and should be run automatically on scheduler.
Any other idea?
Ilin

--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #5  
Old   
frank chang
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-29-2005 , 06:15 PM



Ilin, Your earlier post did not mention whether the first row of your
exported text file has column names. In the DTS text file connection
properties , one can specify whether the first row has column names. The
method which I described in the earlier post assumes the first row has no
column names. If your text file output has column headers , then Allan
Mitchell's post is your answer. Thank you.

"Ilin Start via SQLMonster.com" wrote:

Quote:
Thanks, but unfortunately I can not do this. It should be done inside of data
transformation task and should be run automatically on scheduler.
Any other idea?
Ilin

--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #6  
Old   
frank chang
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-29-2005 , 06:40 PM



Ilin, If the first row of your text file has column names, then you can still
implement Allan Mitchell's suggestion in an Active Script task at the finish
of your DTS workflow by appending the data file to the title file. This
workflow can still run automatically on the scheduler. The following code is
similar to an Active X script I just tested.

Const ForAppending = 8
Dim sFileA
Dim sFileB
Dim sFileC
Dim oFS

sFileA = "C:\file1.txt"
sFileB = "C:\file2.txt"
sFileC = "C:\file3.txt"
set oFS = CreateObject("Scripting.FileSystemObject")
oFS.CopyFile sFileA, sFileC
oFS.OpenTextFile(sFileC, ForAppending)_
.Write oFS.OpenTextFile(sFileB).ReadAll

'It is limited to files that will fit within available memory, but that
should be several megabytes in nearly all instances.

"Ilin Start via SQLMonster.com" wrote:

Quote:
Thanks, but unfortunately I can not do this. It should be done inside of data
transformation task and should be run automatically on scheduler.
Any other idea?
Ilin

--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #7  
Old   
Ilin Start via SQLMonster.com
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-29-2005 , 07:17 PM



Thank you very much for all your postings. My first row in a text file has
column names. I already tried to include in stored proc additional column
with report title. But this solution is not good since it appears in each
record of text file. I will try to append files as per your advice.
Also I need to make text file on shared drive read only but be able to run
DTS on scheduler automatically (write this file). Any suggestion how I can
make this file read only but be able to write this file from DTS?
Thanks,
Ilin

--
Message posted via http://www.sqlmonster.com

Reply With Quote
  #8  
Old   
Ilin Start via SQLMonster.com
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-29-2005 , 07:33 PM



I forgot to mention that title of the file should include information
(variables) from my stored proc (date and time). Should I create a separate
stored proc, which will send to the file with title just title line including
variables and then append to it my second file with result set? Do you know
the better way of doing this (hopefully in one shot)? Another question: can I
format file with data in ActiveX script (or somehow) to present a good
picture of the report? I used delimited formatting of text file with tab in
my transformation task.
Thanks,
Ilin

--
Message posted via http://www.sqlmonster.com

Reply With Quote
  #9  
Old   
frank chang
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-30-2005 , 09:17 AM



Ilin, Here is one way to make the DTS-generated text file output read-only.
In the final Active X script after the Data Transformation Task, use
something like:

Function Main()
Const READ_ONLY = 1
Const ForAppending = 8
Dim sFileA
Dim sFileB
Dim sFileC
Dim oFS
Dim objFile


sFileA = "C:\file1.txt"
sFileB = DTSGlobalVariables("FileName").Value
sFileC = "C:\file3.txt"
set oFS = CreateObject("Scripting.FileSystemObject")
oFS.CopyFile sFileA, sFileC
oFS.OpenTextFile(sFileC, ForAppending)_
.Write oFS.OpenTextFile(sFileB).ReadAll

Set objFile = oFS.GetFile("C:\file3.txt")

' Ilin, The following code makes the DTS output text file read-only
If Not objFile.Attributes AND READ_ONLY Then
objFile.Attributes = objFile.Attributes XOR READ_ONLY
End If

Main = DTSTaskExecResult_Success
End Function

Thank you.

"Ilin Start via SQLMonster.com" wrote:

Quote:
Thank you very much for all your postings. My first row in a text file has
column names. I already tried to include in stored proc additional column
with report title. But this solution is not good since it appears in each
record of text file. I will try to append files as per your advice.
Also I need to make text file on shared drive read only but be able to run
DTS on scheduler automatically (write this file). Any suggestion how I can
make this file read only but be able to write this file from DTS?
Thanks,
Ilin

--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #10  
Old   
Ilin Start via SQLMonster.com
 
Posts: n/a

Default Re: Insert Title into text file during transformation task in DTS - 06-30-2005 , 02:02 PM



Thank you very much, it is working. One more question: Is it possible to
restrict permissions on the final file in DTS to read only (not just
attribute because attribute can be easily changed by the user) and if yes how
to do it inside of ActiveX script?

Thanks again,
Ilin

--
Message posted via http://www.sqlmonster.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.