Solved

Add date to file name using DTS in SQL 7.0

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

696 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