1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Set fs = CreateObject("Scripting.FileSystemObject")
Set sqlFile = fs.OpenTextFile(App.Path + "\Script_sql\test.sql")
sqlLine1 = sqlFile.ReadLine
Set connec = New ADODB.Connection
Set rst = New ADODB.Recordset
connec.Open "Driver={SQL Server};Server=" + serveurSql + ";Uid=" + utilisateurSql + ";Pwd=" + pwdSql + ";Database=" + BDDSql
connec.CommandTimeout = 0 'Annul la vérification du TimeOut de 30 sec
'Set rst = connec.Execute(sqlLine1)
rst.Open sqlLine1, connec, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
dossierFileEcriture = fichierSourceIn & "\Ext" & "xxxxxxxxx" & annee & mois & jour
bool = DirExists(dossierFileEcriture)
If bool = True Then
DeleteDirectory (dossierFileEcriture)
MkDir (fichierSourceIn & "\Ext" & "xxxxxxxxx" & annee & mois & jour)
Else
MkDir (fichierSourceIn & "\Ext" & "xxxxxxxxx" & annee & mois & jour)
End If
DossierFinal = fichierSourceIn & "\Ext" & "xxxxxxxxx" & annee & mois & jour
'File_name = Dir(fichierSourceIn & "\Ext" & "xxxxxxxxx" & annee & mois & jour & "\Ext" & "xxxxxxxxx" & annee & mois & jour & ".csv")
file_name = DossierFinal & "\test.csv"
'file_name = "C:\test.csv"
Open file_name For Output As #3
'Close before reopening in another mode.
rst.MoveFirst
Do Until rst.EOF
line = ""
For i = 0 To rst.Fields.Count - 1
If IsNull(rst(i).Value) Then
Astring = Null
Else
Astring = CStr(rst(i).Value)
End If
line = line & sep & quote & Astring & quote
Next i
Print #3, line
'Mid(line, Len(sep) + 1)
rst.MoveNext
Loop
rst.Close
Close #3
sqlFile.Close
connec.Close
Set connec = Nothing
Set sqlFile = Nothing
Set fs = Nothing
ExportCsv = True
Exit Function |
Partager