schnozz
asked on
Add date to file name using DTS in SQL 7.0
I am trying to export data from a table to a .csv file using DTS. The DTS package will be scheduled to run weekly and each file that is created needs to have the current days date included in the filename. For example, the files need to look like filename01012001.csv or similar.
What do I need to add to the query to make this happen?
Thanks in advance
What do I need to add to the query to make this happen?
Thanks in advance
You can write an Active Script Task to change the name of the exported file to one that contains the date.
The following works for me:
Function Main()
Const TempFile = "d:\temp\test.csv"
Dim fs
Dim fil
Set fs = CreateObject("Scripting.Fi leSystemOb ject")
Set fil = fs.GetFile(TempFile)
fil.Name = fs.GetBaseName(TempFile) & Date2MMDDYY & "." & fs.GetExtensionName(TempFi le)
Set fil = Nothing
Set fs = Nothing
Main = DTSTaskExecResult_Success
End Function
Function Date2MMDDYY()
Date2MMDDYY = Pad2Left(Month(Now())) & Pad2Left(Day(Now())) & CStr(Year(Now()))
End Function
Function Pad2Left(ByVal Value)
Pad2Left = Right("0" & CStr(Value), 2)
End Function
Note: VBScript Format is somewhat limited, hence the extra functions. A file name normat of filename112001 would have been easier.
The following works for me:
Function Main()
Const TempFile = "d:\temp\test.csv"
Dim fs
Dim fil
Set fs = CreateObject("Scripting.Fi
Set fil = fs.GetFile(TempFile)
fil.Name = fs.GetBaseName(TempFile) & Date2MMDDYY & "." & fs.GetExtensionName(TempFi
Set fil = Nothing
Set fs = Nothing
Main = DTSTaskExecResult_Success
End Function
Function Date2MMDDYY()
Date2MMDDYY = Pad2Left(Month(Now())) & Pad2Left(Day(Now())) & CStr(Year(Now()))
End Function
Function Pad2Left(ByVal Value)
Pad2Left = Right("0" & CStr(Value), 2)
End Function
Note: VBScript Format is somewhat limited, hence the extra functions. A file name normat of filename112001 would have been easier.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Should be easier.