Solved

Add date to file name using DTS in SQL 7.0

Posted on 2001-08-02
3
257 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:schnozz
  • 2
3 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6345915
Why not use bcp?
Should be easier.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6346000
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.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 6370958
Any news?
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question