Link to home
Start Free TrialLog in
Avatar of schnozz
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
Avatar of nigelrivett
nigelrivett

Why not use bcp?
Should be easier.
Avatar of Anthony Perkins
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.FileSystemObject")
Set fil = fs.GetFile(TempFile)
fil.Name = fs.GetBaseName(TempFile) & Date2MMDDYY & "." & fs.GetExtensionName(TempFile)
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
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial