dbTalk Databases Forums  

How to know the name of a file to be imported by DTS?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss How to know the name of a file to be imported by DTS? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rodney Pacheco P
 
Posts: n/a

Default How to know the name of a file to be imported by DTS? - 09-20-2004 , 04:57 PM







Hello, I' m Rodney and new using DTS and want to create a DTS, it must
import everyday to a table a text file, this file is called "VE" + date of
the day.txt. I know how to load it to the database, but I need to use
vbscript to know which is the name of this file everyday, and change it
automatically.

Somebody can help me?

Thanks a lot!!!




Reply With Quote
  #2  
Old   
Peter A. Schott
 
Posts: n/a

Default Re: How to know the name of a file to be imported by DTS? - 09-20-2004 , 05:48 PM






Take a little bit of work, but not too difficult depending on the date format:

Put this in an ActiveX Task as your first step (or at least before your
import):

Function Main()
Dim oConn, sFilename
Dim Sequence
Dim Minutes
Dim CurrentDate

CurrentDate = DATEADD("h", -2, Now())
'We were working with a time from a server in PST. We're in CST.
'You could probably just use Now()
' Sequence = Hour(CurrentDate)

' If Sequence < 10 Then Sequence = "0" & Sequence

' Minutes = (Minute(CurrentDate) \ 15) * 15
' If Minutes < 10 then Minutes = "0" & Minutes
' sFilename = "DFSPP20030608hhmm.tab"


' Filename format - VEyyyymmddhh.txt
sFilename = "VE" & Right(Year(CurrentDate), 4)
If Month(CurrentDate) < 10 Then sFilename = sFilename & "0" & _
Month(CurrentDate) Else sFilename = sFilename & Month(CurrentDate)
If Day(CurrentDate) < 10 Then sFilename = sFilename & _
"0" & Day(CurrentDate) & ".txt" Else sFilename = sFilename & _
Day(CurrentDate) & ".txt"

DTSGlobalVariables("FileName").value = "'" & sFileName & "';'';'';"

sFilename = "\\servername\sharename\" & _
sFilename

'msgbox sFilename

Set oConn = DTSGlobalVariables.Parent.Connections("ImportFile" )
oConn.DataSource = sFilename

Set oConn = Nothing

Main = DTSTaskExecResult_Success
End Function

"Rodney Pacheco P" <pachecopr (AT) sugeval (DOT) fi.cr> wrote:

Quote:
Hello, I' m Rodney and new using DTS and want to create a DTS, it must
import everyday to a table a text file, this file is called "VE" + date of
the day.txt. I know how to load it to the database, but I need to use
vbscript to know which is the name of this file everyday, and change it
automatically.

Somebody can help me?

Thanks a lot!!!




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.