Solved

Add date to file name using DTS in SQL 7.0

Posted on 2001-08-02
3
248 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

786 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