November 4, 2006 at 3:52 am
Hello,
We have a system that, on a daily basis, produces a flat file of fixed width records from a mainframe. The files are placed in a single directory. The current date is included at the end of the file names in the format of mm|dd|yyyy.
I need to set up a package that will find the latest daily file, and import the contents of the file into a single table. Is it possible to somehow evauate the file names locate the most recent daily file, and then do the import? If not, would there be some way to determine the most recent file by reading the properties of the files to check for the creation date? What could I do about a case where a flat file didn't get created on a given day?
Thank you for your help!
CSDunn
November 4, 2006 at 4:51 am
Use ActiveX Scripting to read files
November 4, 2006 at 5:07 am
Hi cdun2,
TBH, the best way that I've seen this type of scenario handled is to build an AuditLog in your db for these files. The AuditLog tbl would contain a min. of the file name, and creation date (that date will probably match the mm/dd/yy of when the file was generated by the system and placed on the server, but it depends on when you decide to insert the record into the AuditLog). Every time a new file is generated by the system, the AuditLog is updated with that information.
Then you could build a DTS pkg that reads that table looking for the entry with the creation date that matches the datetime that you specify in your code (max(creationdate) prob. wouldn't work for your scenario since there are apparently occasions when a new file won't be generated). When the date values match, you could pass the file name as a variable to your pkg so that the code would import that specific file.
Does this make any sense?
November 6, 2006 at 3:00 am
Yes, thanks for being so helpful. I'd also be iterested in seeing an Active X script that could do this kind of thing. SSIS appears to have some build in functionality in it for just this kind of situation, but that will have to wait.
My goal is to have this process totally automated, and eventually (early next year) have this working in SSIS.
Thanks again for your help!
CSDunn
November 7, 2006 at 4:13 pm
If you know of a documented example of this that I might be able to find on the web, could you point me to the URL? If not, and if you wouldn't mind, could you offer more detail on how I might accomplish this?
This is my first attempt at doing something like this (beyond basics) in DTS.
Thanks again for your help!
CSDunn
November 7, 2006 at 5:34 pm
You can use xp_getfiledetails in an Execute SQL task to get the properties of a file. I don't have the details handy, but you can search this site for references.
Greg
Greg
November 9, 2006 at 10:12 am
Here's an active x script file I use:
Function Main() Dim tMain tMain = DTSTaskExecResult_Success If isCurrentFile("FLATFILE.TXT") Then tMain = DTSTaskExecResult_Success Else tMain = DTSTaskExecResult_Failure End If Main = tMain End FunctionFunction isCurrentFile(strPath, strFile) Dim fso Dim tFile Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(strPath & strFile) Then Set tFile = fso.GetFile(strPath & strFile) If formatDateTime(tFile.DateLastModified,2) = formatDateTime(Date,2) Then Set tFile = Nothing Set fso = Nothing isCurrentFile = True Else Set tFile = Nothing Set fso = Nothing isCurrentFile = False End If Else Set tFile = Nothing Set fso = Nothing isCurrentFile = False End If End Function
October 30, 2007 at 5:36 pm
Anyone knows how to handle this in SSIS?
October 31, 2007 at 8:19 am
Check out the information in this post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1209825&SiteID=1
There is at least one other URL within this post that you should also look at.
CSDunn
November 1, 2007 at 8:16 am
CSDunn,
These sites may be of use:
DTS Resources
SSIS Resources
SQLIS Wiki
wiki.sqlis.com
Best of Luck.
"Key"
MCITP: DBA, MCSE, MCTS: SQL 2005, OCP
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply