executer un script SQL à partir de Excel
Bonjour ,
Je travaille sur Excel 2007, je dois executer une requête à partir d'un boulon sur Excel qui utilise une macro.
j'ai fait un code et il marche hyper bien.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Sub Teste_Emprunt()
' Declare the QueryTable object
Dim qt As QueryTable
' Set up the SQL Statement
sqlstring1 = "select distinct(EE.IdEmprunt),CC.idClient, CC.LbNom, EE.CdRefClient, BB.LbNomCourt as Banque, EE.DtRealisation, EE.DtFinDette from _Ref_EtatEmprunt RE, Emprunt EE join Client CC on EE.idClient = CC.idClient join Banque BB on EE.idBanque = BB.idBanque join EcheanceAmortissement EA on EE.IdEmprunt = EA.IdEmprunt where CC.IdTypeCompte=0 and EA.FlCRD<0 and RE.IdEtatEmprunt in (1) ORDER BY CC.IdClient ASC "
sqlstring2 = "select * from Client"
' Set up the connection string, reference an ODBC connection
' There are several ways to do this
' Leave the name and password blank for NT authentication
connstring1 = _
"ODBC;DSN=pubs;UID=;PWD=;Database="
' Now implement the connection, run the query, and add
' the results to the spreadsheet starting at row A1
With Sheets("Data1").QueryTables.Add(Connection:=connstring1, Destination:=Range("Data1!A3"), Sql:=sqlstring1)
.Refresh
End With
End Sub |
le problème c'est que au lieu d'écrire la requête dans le code "sqlstring2 = "select * from Client"", je veux faire "sqlstring2 = "c:\script.sql""
==> je veux exécuter le script que j'ai dans un fichier .sql.
je ne sais pas comment faire. :arf:
Aidez moi SVP :?
Merci d'avance