dbTalk Databases Forums  

Can DTS output to variant text file names each time it runs?

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


Discuss Can DTS output to variant text file names each time it runs? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jamie
 
Posts: n/a

Default Can DTS output to variant text file names each time it runs? - 06-23-2005 , 03:49 PM






Hi, there,

I have one DTS runs every day to generate one text file from one table in a
database of SQL Server 2000. The output file path I use is
\\web2\export\report.txt. I schedule the DTS to run at 10:00pm every day,
and each time it runs it will generate a text file "report.txt" on the
folder "\web2\export".

My problem is, I have to rename the output file to a different one like
"20050623_report.txt" every day, otherwise the output file will be
overwritten by the next run of the DTS.

My question is, is there a way to generate a text file with the date of the
DTS run attached to it? (For example: today the DTS will generate a file
name "20050623_report.txt", while tomorrow it will generate a new file name
"20050624_report.txt" automatically). Because I don't want the old files to
be overwritten.

Thanks so much in advance,

Jamie



Reply With Quote
  #2  
Old   
Francesco Anti
 
Posts: n/a

Default Re: Can DTS output to variant text file names each time it runs? - 06-24-2005 , 03:06 AM






You can use an "ActiveX script task" to fill a Global variable with the file
name and then "Dynamic Properties Task" to assign this value to the
destination connection.

Francesco Anti

"Jamie" <gsadd (AT) yahoo (DOT) com> wrote

Quote:
Hi, there,

I have one DTS runs every day to generate one text file from one table in
a database of SQL Server 2000. The output file path I use is
\\web2\export\report.txt. I schedule the DTS to run at 10:00pm every day,
and each time it runs it will generate a text file "report.txt" on the
folder "\web2\export".

My problem is, I have to rename the output file to a different one like
"20050623_report.txt" every day, otherwise the output file will be
overwritten by the next run of the DTS.

My question is, is there a way to generate a text file with the date of
the DTS run attached to it? (For example: today the DTS will generate a
file name "20050623_report.txt", while tomorrow it will generate a new
file name "20050624_report.txt" automatically). Because I don't want the
old files to be overwritten.

Thanks so much in advance,

Jamie




Reply With Quote
  #3  
Old   
PaulaPompey
 
Posts: n/a

Default RE: Can DTS output to variant text file names each time it runs? - 06-24-2005 , 06:27 AM



To add to Francesco's comments, you might find the following link useful if
you are new to ActiveX scripts:
http://www.w3schools.com/vbscript/default.asp

Alternatively, here is a bit of VB you can edit that I have used in an
ActiveX script to name output files:
'************************************************* ***********
' Visual Basic ActiveX Script
'************************************************* ***********

Function Main()
Dim objConn, strFilename


' Filename format - \\Server\Drive\Folder\Filename_YYYYMMDD.txt
'Start of destination file name
strFilename = "\\Server\Drive\Folder\Filename_"
'Add 4 digit year + 2 digit month + 2 digit day to file name
strFilename = strFilename & Year(Now()) & Right("0" & Month(Now()),2) &
Right("0" & Day(Now()),2)
'Add file extension to file name
strFilename = strFilename & '.txt'

'Set the destination for the connection to the string just built above
Set objConn = DTSGlobalVariables.Parent.Connections("TextFileCon nectionName")
objConn.DataSource = strFilename

'Tidy up - clear connection object
Set objConn = Nothing

Main = DTSTaskExecResult_Success

End Function


Hope this helps

Paula

"Jamie" wrote:

Quote:
Hi, there,

I have one DTS runs every day to generate one text file from one table in a
database of SQL Server 2000. The output file path I use is
\\web2\export\report.txt. I schedule the DTS to run at 10:00pm every day,
and each time it runs it will generate a text file "report.txt" on the
folder "\web2\export".

My problem is, I have to rename the output file to a different one like
"20050623_report.txt" every day, otherwise the output file will be
overwritten by the next run of the DTS.

My question is, is there a way to generate a text file with the date of the
DTS run attached to it? (For example: today the DTS will generate a file
name "20050623_report.txt", while tomorrow it will generate a new file name
"20050624_report.txt" automatically). Because I don't want the old files to
be overwritten.

Thanks so much in advance,

Jamie




Reply With Quote
  #4  
Old   
Jamie
 
Posts: n/a

Default Re: Can DTS output to variant text file names each time it runs? - 06-24-2005 , 09:23 AM



Thank you so much for the detailed help! It's really helpful.

Jamie
"PaulaPompey" <PaulaPompey (AT) discussions (DOT) microsoft.com> wrote

Quote:
To add to Francesco's comments, you might find the following link useful
if
you are new to ActiveX scripts:
http://www.w3schools.com/vbscript/default.asp

Alternatively, here is a bit of VB you can edit that I have used in an
ActiveX script to name output files:
'************************************************* ***********
' Visual Basic ActiveX Script
'************************************************* ***********

Function Main()
Dim objConn, strFilename


' Filename format - \\Server\Drive\Folder\Filename_YYYYMMDD.txt
'Start of destination file name
strFilename = "\\Server\Drive\Folder\Filename_"
'Add 4 digit year + 2 digit month + 2 digit day to file name
strFilename = strFilename & Year(Now()) & Right("0" & Month(Now()),2) &
Right("0" & Day(Now()),2)
'Add file extension to file name
strFilename = strFilename & '.txt'

'Set the destination for the connection to the string just built above
Set objConn =
DTSGlobalVariables.Parent.Connections("TextFileCon nectionName")
objConn.DataSource = strFilename

'Tidy up - clear connection object
Set objConn = Nothing

Main = DTSTaskExecResult_Success

End Function


Hope this helps

Paula

"Jamie" wrote:

Hi, there,

I have one DTS runs every day to generate one text file from one table in
a
database of SQL Server 2000. The output file path I use is
\\web2\export\report.txt. I schedule the DTS to run at 10:00pm every day,
and each time it runs it will generate a text file "report.txt" on the
folder "\web2\export".

My problem is, I have to rename the output file to a different one like
"20050623_report.txt" every day, otherwise the output file will be
overwritten by the next run of the DTS.

My question is, is there a way to generate a text file with the date of
the
DTS run attached to it? (For example: today the DTS will generate a file
name "20050623_report.txt", while tomorrow it will generate a new file
name
"20050624_report.txt" automatically). Because I don't want the old files
to
be overwritten.

Thanks so much in advance,

Jamie






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.