dbTalk Databases Forums  

How to put today's DATE in filename?

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


Discuss How to put today's DATE in filename? in the microsoft.public.sqlserver.dts forum.



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

Default How to put today's DATE in filename? - 08-01-2003 , 12:48 PM






I'm using DTS to export data to a csv file. This will be scheduled to
create a new file every day.

How do I name each file with today's date?

eg: 01012002.csv, 02012003.csv etc?

Thanks
Leslie

Reply With Quote
  #2  
Old   
JFB
 
Posts: n/a

Default Re: How to put today's DATE in filename? - 08-01-2003 , 04:04 PM






Hi Leslie,
You need to use activeX script task to to this.
Regards.
JFB

Here is an example:

Function Main()
Dim oConn, sFilename

' Filename format - exyymmdd.log
sFilename = "ex" & Right(Year(Now()), 2)
If Month(Now()) < 10 Then sFilename = sFilename & "0" & _
Month(Now()) Else sFilename = sFilename & Month(Now())
If Day(Now()) < 10 Then sFilename = sFilename & _
"0" & Day(Now()) Else sFilename = sFilename & Day(Now())
sFilename = DTSGlobalVariables("LogFilePath").Value & _
sFilename & ".log"

Set oConn = DTSGlobalVariables.Parent.Connections("Text File (Source)")
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function


<les> wrote

Quote:
I'm using DTS to export data to a csv file. This will be scheduled to
create a new file every day.

How do I name each file with today's date?

eg: 01012002.csv, 02012003.csv etc?

Thanks
Leslie



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

Default Re: How to put today's DATE in filename? - 08-01-2003 , 07:38 PM



Thanks JFB.

I've only got as far as a simple DTS package that connects to a
database then copies some data to a csv file. I have tried adding an
activex script task based on your example to run on completion of the
text file(destination) connection, but I don't know how to configure
it.

Do I have to create DTSGlobalVariables?
Is Logfilepath the path to my csv file? eg: C:\folder\myfile.csv
What is: DTSGlobalVariables.Parent.Connections("Text File (Source)")

Leslie


On Fri, 1 Aug 2003 17:04:48 -0400, "JFB" <jfb2002 (AT) directvinternet (DOT) com>
wrote:

Quote:
Hi Leslie,
You need to use activeX script task to to this.
Regards.
JFB

Here is an example:

Function Main()
Dim oConn, sFilename

' Filename format - exyymmdd.log
sFilename = "ex" & Right(Year(Now()), 2)
If Month(Now()) < 10 Then sFilename = sFilename & "0" & _
Month(Now()) Else sFilename = sFilename & Month(Now())
If Day(Now()) < 10 Then sFilename = sFilename & _
"0" & Day(Now()) Else sFilename = sFilename & Day(Now())
sFilename = DTSGlobalVariables("LogFilePath").Value & _
sFilename & ".log"

Set oConn = DTSGlobalVariables.Parent.Connections("Text File (Source)")
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function


les> wrote

I'm using DTS to export data to a csv file. This will be scheduled to
create a new file every day.

How do I name each file with today's date?

eg: 01012002.csv, 02012003.csv etc?

Thanks
Leslie



Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: How to put today's DATE in filename? - 08-02-2003 , 05:47 AM



In article <j81mivo6ststoqmslr1ul12pqjn9pll2so (AT) 4ax (DOT) com>, les@?.?.invalid
writes
Quote:
Thanks JFB.

I've only got as far as a simple DTS package that connects to a
database then copies some data to a csv file. I have tried adding an
activex script task based on your example to run on completion of the
text file(destination) connection, but I don't know how to configure
it.

Do I have to create DTSGlobalVariables?
Is Logfilepath the path to my csv file? eg: C:\folder\myfile.csv
What is: DTSGlobalVariables.Parent.Connections("Text File (Source)")

Leslie

DTSGlobalVariables is an implicit handle to the package GlobalVariables
collection.

In that example it expects you to have a global variable called
LogFilePath which holds the file path. The file name is derived in code,
the statements above the global variable reference.

DTSGlobalVariables.Parent.Connections("Text File (Source)") is a
reference to your text file connection.

DTSGLobalVariables gives us the packages global variables collection.
Parent is the parent of the global variables collection, so this gives
us the package.
Connections is a reference to package's Connections collection, and you
are referencing the connection named Text File (Source). You may need to
change this to match the name of the text file connection in your
package.

That section could also be written like this-

' Get current package
Set oPkg = DTSGlobalVariables.Parent

'Get Connections collection
Set oConns = oPkg.Connections

' Get my text file Connection by name
Set oConn = oConns("Text File (Source)")

' Set the DataSource (filename) property of my connection
oConn.DataSource = "C:\Fred.txt"


Some similar resources-

How can I change the filename for a text file connection?
http://www.sqldts.com/default.aspx?6,101,200,0,1

Working with files and the FileSystemObject
http://www.sqldts.com/default.aspx?6,101,292,0,1

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com




Reply With Quote
  #5  
Old   
JFB
 
Posts: n/a

Default Re: How to put today's DATE in filename? - 08-02-2003 , 05:52 AM



Hi Leslie,
If you create a xls file in you DTS pkg you should have this:
1.Create table
2.Connection1 (odbc)
3.Connection 2 (excel file)
Create a ActiveX script task ( 4. ActiveX script task)
Now you should refer this line to you excel file name.
DTSGlobalVariables.Parent.Connections("Connection 2")
You dont need to create a Global Variable, this line only gets the
connection name into you active x script variable oConn.
I hope this is clear for you.
JFB

<les> wrote

Quote:
Thanks JFB.

I've only got as far as a simple DTS package that connects to a
database then copies some data to a csv file. I have tried adding an
activex script task based on your example to run on completion of the
text file(destination) connection, but I don't know how to configure
it.

Do I have to create DTSGlobalVariables?
Is Logfilepath the path to my csv file? eg: C:\folder\myfile.csv
What is: DTSGlobalVariables.Parent.Connections("Text File (Source)")

Leslie


On Fri, 1 Aug 2003 17:04:48 -0400, "JFB" <jfb2002 (AT) directvinternet (DOT) com
wrote:

Hi Leslie,
You need to use activeX script task to to this.
Regards.
JFB

Here is an example:

Function Main()
Dim oConn, sFilename

' Filename format - exyymmdd.log
sFilename = "ex" & Right(Year(Now()), 2)
If Month(Now()) < 10 Then sFilename = sFilename & "0" & _
Month(Now()) Else sFilename = sFilename & Month(Now())
If Day(Now()) < 10 Then sFilename = sFilename & _
"0" & Day(Now()) Else sFilename = sFilename & Day(Now())
sFilename = DTSGlobalVariables("LogFilePath").Value & _
sFilename & ".log"

Set oConn = DTSGlobalVariables.Parent.Connections("Text File (Source)")
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function


les> wrote

I'm using DTS to export data to a csv file. This will be scheduled to
create a new file every day.

How do I name each file with today's date?

eg: 01012002.csv, 02012003.csv etc?

Thanks
Leslie





Reply With Quote
  #6  
Old   
les
 
Posts: n/a

Default Re: How to put today's DATE in filename? - 08-02-2003 , 08:59 AM



Thanks both of you. I have it working now with:

Function Main()
Dim oConn, sFilename

' Filename format - exyymmdd.log
sFilename = "ST" & Right(Year(Now()), 2)
If Month(Now()) < 10 Then sFilename = sFilename & "0" & _
Month(Now()) Else sFilename = sFilename & Month(Now())
If Day(Now()) < 10 Then sFilename = sFilename & _
"0" & Day(Now()) Else sFilename = sFilename & Day(Now())
sFilename = DTSGlobalVariables("csvpath").Value & _
sFilename & ".csv"

Set oConn = DTSGlobalVariables.Parent.Connections("Text File
(Destination)")
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function


Leslie


On Sat, 2 Aug 2003 06:52:05 -0400, "JFB" <jfb2002 (AT) directvinternet (DOT) com>
wrote:

Quote:
Hi Leslie,
If you create a xls file in you DTS pkg you should have this:
1.Create table
2.Connection1 (odbc)
3.Connection 2 (excel file)
Create a ActiveX script task ( 4. ActiveX script task)
Now you should refer this line to you excel file name.
DTSGlobalVariables.Parent.Connections("Connection 2")
You dont need to create a Global Variable, this line only gets the
connection name into you active x script variable oConn.
I hope this is clear for you.
JFB

les> wrote

Thanks JFB.

I've only got as far as a simple DTS package that connects to a
database then copies some data to a csv file. I have tried adding an
activex script task based on your example to run on completion of the
text file(destination) connection, but I don't know how to configure
it.

Do I have to create DTSGlobalVariables?
Is Logfilepath the path to my csv file? eg: C:\folder\myfile.csv
What is: DTSGlobalVariables.Parent.Connections("Text File (Source)")

Leslie


On Fri, 1 Aug 2003 17:04:48 -0400, "JFB" <jfb2002 (AT) directvinternet (DOT) com
wrote:

Hi Leslie,
You need to use activeX script task to to this.
Regards.
JFB

Here is an example:

Function Main()
Dim oConn, sFilename

' Filename format - exyymmdd.log
sFilename = "ex" & Right(Year(Now()), 2)
If Month(Now()) < 10 Then sFilename = sFilename & "0" & _
Month(Now()) Else sFilename = sFilename & Month(Now())
If Day(Now()) < 10 Then sFilename = sFilename & _
"0" & Day(Now()) Else sFilename = sFilename & Day(Now())
sFilename = DTSGlobalVariables("LogFilePath").Value & _
sFilename & ".log"

Set oConn = DTSGlobalVariables.Parent.Connections("Text File (Source)")
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function


les> wrote

I'm using DTS to export data to a csv file. This will be scheduled to
create a new file every day.

How do I name each file with today's date?

eg: 01012002.csv, 02012003.csv etc?

Thanks
Leslie





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.