Solved

Add date to file name using DTS in SQL 7.0

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now