Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Antonio
Posting Yak Master
168 Posts |
Posted - 2006-07-06 : 12:58:57
|
Hi there,I have a simple DTS package (SQL Server 2000) which outputs some data to a CSV file. What I want to do is save the CSV file with today's date as part of the name. How to do this?!Do I have to use ActiveX script to accomplish this?Thanks in advance._________________________________________________________________________________________________________________________Inability is a disaster; patience is bravery; abstinence is a treasure, self-restraint is a shield; and the best companion is submission to Divine Will. |
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2006-07-06 : 14:09:32
|
Yeah, create an activex task containing a sub to do something along these lines:Dim objPackageDim objTextConDim datDateDim strDateDim strYearDim strMonthDim strDayDim strFilePathDim strFileNameDim strFileSuffixstrPath = DTSGlobalVariables("gv_FilePath").ValuestrFilename = DTSGlobalVariables("gv_FileName").ValuedatDate = Date()strYear = CStr(Year(datDate))strMonth = CStr(Month(datDate))strDay = CStr(Day(datDate))strDate = strYear & strMonth & strDaystrFileName = strFileName & "_" & strDate & ".csv"strFileName = strFilePath & strFileName & strFileSuffixSet objPackage = DTSGlobalVariables.ParentSet objTextCon = objPackage.Connections("MyTextConnection") 'Substituting the name of your connection!!objTextCon.DataSource = strFileNameSet objTextCon = NothingSet objPackage = Nothing Then create a precedence constraint to ensure it runs before your (I assume) transform task.Mark |
 |
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2006-07-06 : 15:35:54
|
I do a little differently, I setup the dates on the DTS Global Variable and use that on each step of the package for other reasons.If you take this route, use the first script as the first step of the dts and the second one after you have exported the data to the file.See scripts below:This code will set your DTS Global Variables (date variables):'**********************************************************************' Visual Basic ActiveX Script'************************************************************************Function Main() if not (isdate(dtsglobalvariables("YesterdaysDate"))) then dtsglobalvariables("YesterdaysDate")=formatdatetime(date()-1,2) dtsglobalvariables("DateInPreviousMonth") = DATEADD ("m", -1, date ()) end if dtsglobalvariables("TodaysDate") =formatdatetime(cdate(dtsglobalvariables("YesterdaysDate"))+1,2) Main = DTSTaskExecResult_SuccessEnd FunctionThis code will rename your file:'**********************************************************************' Visual Basic ActiveX Script'************************************************************************Function Main()theday = Day(dtsglobalvariables("TodaysDate"))themonth = Month(dtsglobalvariables("TodaysDate"))theyear = Year(dtsglobalvariables("TodaysDate"))If Len(theday) = 1 Then theday = "0" & thedayIf Len(theprevday) = 1 Then theprevday = "0" & theprevdayIf Len(themonth) = 1 Then themonth = "0" & themonthfiletoget1 = "Report.XLS"filetoget2 = "Report_" & themonth & theday & theyear & ".XLS"Dim fsSet fs = CreateObject("Scripting.FileSystemObject")destinationfilename = "C:\dir1\subdir1\" & filetoget2if fs.fileexists(destinationfilename) then fs.deletefile destinationfilenametemplatefilename = "C:\dir1\subdir1\" & filetoget1if fs.fileexists(templatefilename) then fs.copyfile templatefilename, destinationfilename Main = DTSTaskExecResult_SuccessMain = DTSTaskExecResult_SuccessMain = DTSTaskExecResult_SuccessEnd Function---Thanks!Igor. |
 |
|
|
|
|