I have the following VB code in a script task in an SSIS package: For Each myFile In files fileName = myFile.ToString dateStamp = Mid(fileName, (fileName.LastIndexOf("_") + 2), 8) dateStamp2 = Mid(fileName, (fileName.LastIndexOf("_") + 1), 9) If IsNumeric(dateStamp) Then If strWeekday = "Monday" And CDbl(dateStamp) < CDbl(strDateToday) Then Now = DateTime.Now sqlCmdText = "IF EXISTS (SELECT FileName FROM R9.R9RefreshExpectedFiles WHERE FileName = " & fileName.Replace(dateStamp2, "").Replace("D:\SSIS\R9\Hewitt\Import\", "") & ")" sqlCmdText = sqlCmdText & " INSERT INTO R9.DataRefreshErrors([Date],Task,ObjectTable,RuleID,ErrorNumber,ErrorMessage) Values('" & Now & "','Check File Dates','','','','" & fileName.Replace("D:\SSIS\R9\Hewitt\Import\", "") & " may be outdated.')" sqlCmd = New SqlCommand(sqlCmdText, sqlConn) rdrReader = sqlCmd.ExecuteReader() rdrReader.Close() ElseIf strWeekday = "Saturday" And CDbl(dateStamp) < CDbl(strDateToday) - 1 Then Now = DateTime.Now sqlCmdText = "IF EXISTS (SELECT FileName FROM R9.R9RefreshExpectedFiles WHERE FileName = " & fileName.Replace(dateStamp2, "").Replace("D:\SSIS\R9\Hewitt\Import\", "") & ")" sqlCmdText = sqlCmdText & " INSERT INTO R9.DataRefreshErrors([Date],Task,ObjectTable,RuleID,ErrorNumber,ErrorMessage) Values('" & Now & "','Check File Dates','','','','" & fileName.Replace("D:\SSIS\R9\Hewitt\Import\", "") & " may be outdated.')" sqlCmd = New SqlCommand(sqlCmdText, sqlConn) rdrReader = sqlCmd.ExecuteReader() rdrReader.Close() End If End If Next
There are 110 files in the "files" directory, and many of them meet the conditions of the IF statement, but the loop is only executing once. Does anybody see what I'm missing?