March 6, 2010 at 10:20 am
Function Main()
Dim objFSO 'File System Object
Dim outputfile 'Output File Name
Dim adoconnection 'ADO Connection Handle
Dim rs 'ADO Recordset object
Dim sSql 'A String variable to store SQL statements
Dim sGroupDetailRecord 'Variable to store group detail header
Dim sCustomerHeader 'Variable to store customer header record
Dim lnFieldIndex 'Integer field to iterate recordset columns
Dim sClientId 'Variable to store ClientID
Dim sDateTimeString 'A variable to store current date in YYYYMMDD format
Dim lnClientCount'Variable to hold the count of each client Id
Dim sOutputFileName
Dim lnHeaderCount
sDateTimeString = datepart("YYYY",Date) & Right("00" & DatePart("m",Date),2) & Right("00" & DatePart("d",Date),2)
'Inititalize and open the output file
Set objFSO = CreateObject("Scripting.FileSystemObject")
sOutputFileName = DTSGlobalVariables("OutputFileName").Value
'delete the file if it is already found
if objFSO.FileExists(sOutputFileName) then
objFSO.DeleteFile sOutputFileName
end if
Set outputfile = objFSO.OpenTextFile(sOutputFileName, 2,True)
'Build the Header Record
tmpstr = "0001420000G" + sDateTimeString + "000000" + sDateTimeString + sDateTimeString + Space(209)
sSql = "exec dbo.pr_Extract_Args_Grps401_Read"
'Establish an ADO connection
Set adoconnection = CreateObject("ADODB.Connection")
adoconnection.Open DTSGlobalVariables("ConnectionString")
adoConnection.CommandTimeout = 300
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.CursorType = 0
Setrs.ActiveConnection = adoconnection
rs.open sSql
' Set rs = adoconnection.Execute(sSql, , 0) ' opened a forward only cursor
Set rs.ActiveConnection = Nothing
If Not rs.EOF Then
outputfile.writeline tmpstr 'write the header record
sClientId = ""
lnClientCount = 0
Do While Not rs.EOF
sGroupDetailRecord = ""
' Build one Customer Header Record for every client ID
If sClientId <> rs(2) Then
'First write the previous client trailer record
If lnClientCount <> 0 Then
outputfile.writeline "900142" + sClientId + Right("000000" + CStr(lnClientCount),7)+space(233)
lnClientCount = 0
End if
sClientId = rs(2)
'Customer Header Record
sCustomerHeader = "010142" + sClientId + "F" + sDateTimeString + "000000" + sDateTimeString + sDateTimeString + Space(209)
outputfile.writeline sCustomerHeader
lnHeaderCount = lnHeaderCount+1
End If
For lnFieldIndex = 0 To rs.Fields.Count - 1
sGroupDetailRecord = sGroupDetailRecord + rs(lnFieldIndex)
Next
outputfile.writeline sGroupDetailRecord
lnClientCount = lnClientCount + 1
rs.MoveNext
Loop
'write the last client Trailer Record
outputfile.writeline "900142" + sClientId + Right("000000" + CStr(lnClientCount),7)+space(233)
'write the file trailer record
outputfile.writeline "9901420000" + Right("000000" + CStr(lnHeaderCount),7)+space(233)
outputfile.Close 'close the output file
else
'No Data returned by the SP.
'Write a blan file with only the file header and file trailer information
outputfile.writeline tmpstr 'write the header record
outputfile.writeline "9901420000" + Right("000000" + CStr(lnHeaderCount),7)+space(233)
outputfile.Close 'close the output file
End If
rs.Close
Set rs = Nothing
adoconnection.Close
Set adoconnection = Nothing
Main = DTSTaskExecResult_Success
End Function
March 7, 2010 at 12:27 am
Why did you post this?
March 7, 2010 at 12:36 am
Can any one please tell me how to convert this Activex script into SSIS tasks.
March 8, 2010 at 12:32 am
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply