访问VBA SQL字符串太长

时间:2011-12-02 16:30:35

标签: sql ms-access excel-vba query-string vba

我有一个Excel 2003 VBA程序,它以这样的方式创建一个SQL字符串:

OrdresPlanif = ""
Do While Cells(i, 1).Value <> "CODES TEMPS"
    noOrdre = Cells(i, 4).Value
    If noOrdre <> "" Then
        OrdresPlanif = OrdresPlanif + "(Ordre.Ordre) <> " & noOrdre & " And " ' String for the orders shecduled
    End If
    i = i + 1
Loop
OrdresPlanif = Left(OrdresPlanif, Len(OrdresPlanif) - 5) ' Remove last "and" from string OrdresNonPlanif
SQLnonPlanif = "SELECT Ordre.Ordre, Sum(Ordre.Duree) AS SommeDeDuree" _
                & " FROM Ordre" _
                & " WHERE (((Ordre.Date) >= #" & Date1 & "# And (Ordre.Date) <= #" & Date2 & "#) AND (" & MatOrString & ") And (" & OrdresPlanif & "))" _
                & " GROUP BY Ordre.Ordre;"
Set rsNonPlanif = cn.Execute(SQLnonPlanif)

问题是,在SQL语句中添加大约100~150个noOrdre和~15个MatOrString。错误&#34;复杂的SQL语句&#34;从Access(2003)回来。我一直在寻找解决方案,但人们正在谈论连接很多,但它似乎不是一个可行的解决方案,因为我从循环创建我的字符串。
有没有办法解决这个问题?或者我的策略是错误的,首先是?

[编辑]

这里我添加了一个从我的代码生成的示例查询。当我尝试将其粘贴到访问权限时,会出现同样的错误。

  

SELECT Ordre.Ordre,Sum(Ordre.Duree)作为来自Ordre WHERE的SommeDeDuree   (((Ordre.Date)&gt; =#07/11/2011#And(Ordre.Date)&lt; =#14/11/2011#)AND   (Ordre.Matricule = 257 OR Ordre.Matricule = 516 OR Ordre.Matricule = 591 OR   Ordre.Matricule = 1797 OR Ordre.Matricule = 1802 OR Ordre.Matricule = 1828   或Ordre.Matricule = 2061或Ordre.Matricule = 2070或   Ordre.Matricule = 2085或Ordre.Matricule = 2103 OR Ordre.Matricule = 2142   或Ordre.Matricule = 2211或Ordre.Matricule = 2344或   Ordre.Matricule = 2436 OR Ordre.Matricule = 2471)和((Ordre.Ordre)&lt;&gt;   10000477和(Ordre.Ordre)&lt;&gt; 11146074和(Ordre.Ordre)&lt;&gt; 11146315   和(Ordre.Ordre)&lt;&gt; 11146662和(Ordre.Ordre)&lt;&gt; 11146689和   (Ordre.Ordre)&lt;&gt; 11147233和(Ordre.Ordre)&lt;&gt; 11147616和   (Ordre.Ordre)&lt;&gt; 11148129和(Ordre.Ordre)&lt;&gt; 11147923和   (Ordre.Ordre)&lt;&gt; 11147924和(Ordre.Ordre)&lt;&gt; 11147925和   (Ordre.Ordre)&lt;&gt; 11147192和(Ordre.Ordre)&lt;&gt; 11147206和   (Ordre.Ordre)&lt;&gt; 11147217和(Ordre.Ordre)&lt;&gt; 11147219和   (Ordre.Ordre)&lt;&gt; 11147220和(Ordre.Ordre)&lt;&gt; 11147221和   (Ordre.Ordre)&lt;&gt; 11147255和(Ordre.Ordre)&lt;&gt; 11147263和   (Ordre.Ordre)&lt;&gt; 11147265和(Ordre.Ordre)&lt;&gt; 11147292而且   (Ordre.Ordre)&lt;&gt; 11147295和(Ordre.Ordre)&lt;&gt; 11147297和   (Ordre.Ordre)&lt;&gt; 11147298和(Ordre.Ordre)&lt;&gt; 11147299和   (Ordre.Ordre)&lt;&gt; 11147300和(Ordre.Ordre)&lt;&gt; 11146863和   (Ordre.Ordre)&lt;&gt; 11146864和(Ordre.Ordre)&lt;&gt; 11147252和   (Ordre.Ordre)&lt;&gt; 11147547和(Ordre.Ordre)&lt;&gt; 11147550和   (Ordre.Ordre)&lt;&gt; 11147551和(Ordre.Ordre)&lt;&gt; 11147556和   (Ordre.Ordre)&lt;&gt; 11147588和(Ordre.Ordre)&lt;&gt; 11147594和   (Ordre.Ordre)&lt;&gt; 11147595和(Ordre.Ordre)&lt;&gt; 11147610和   (Ordre.Ordre)&lt;&gt; 11147684和(Ordre.Ordre)&lt;&gt; 11147685和   (Ordre.Ordre)&lt;&gt; 11147696和(Ordre.Ordre)&lt;&gt; 11147697和   (Ordre.Ordre)&lt;&gt; 11147698和(Ordre.Ordre)&lt;&gt; 11147699和   (Ordre.Ordre)&lt;&gt; 11147700和(Ordre.Ordre)&lt;&gt; 11147702和   (Ordre.Ordre)&lt;&gt; 11147720和(Ordre.Ordre)&lt;&gt; 11147972和   (Ordre.Ordre)&lt;&gt; 11147974和(Ordre.Ordre)&lt;&gt; 11147975和   (Ordre.Ordre)&lt;&gt; 11147976和(Ordre.Ordre)&lt;&gt; 11147977和   (Ordre.Ordre)&lt;&gt; 11147978和(Ordre.Ordre)&lt;&gt; 11147979和   (Ordre.Ordre)&lt;&gt; 11147980和(Ordre.Ordre)&lt;&gt; 11147983和   (Ordre.Ordre)&lt;&gt; 11147985和(Ordre.Ordre)&lt;&gt; 11147990和   (Ordre.Ordre)&lt;&gt; 11147991和(Ordre.Ordre)&lt;&gt; 12156143和   (Ordre.Ordre)&lt;&gt; 12156147和(Ordre.Ordre)&lt;&gt; 12156151和   (Ordre.Ordre)&lt;&gt; 12155605和(Ordre.Ordre)&lt;&gt; 12155606和   (Ordre.Ordre)&lt;&gt; 12155607和(Ordre.Ordre)&lt;&gt; 12155608和   (Ordre.Ordre)&lt;&gt; 12155609和(Ordre.Ordre)&lt;&gt; 12155610和   (Ordre.Ordre)&lt;&gt; 12155611和(Ordre.Ordre)&lt;&gt; 12155616和   (Ordre.Ordre)&lt;&gt; 12155436和(Ordre.Ordre)&lt;&gt; 12155437和   (Ordre.Ordre)&lt;&gt; 12155438和(Ordre.Ordre)&lt;&gt; 12155764和   (Ordre.Ordre)&lt;&gt; 12155765和(Ordre.Ordre)&lt;&gt; 12155444和   (Ordre.Ordre)&lt;&gt; 12155429和(Ordre.Ordre)&lt;&gt; 12155430和   (Ordre.Ordre)&lt;&gt; 12155431和(Ordre.Ordre)&lt;&gt; 12155433和   (Ordre.Ordre)&lt;&gt; 12155434和(Ordre.Ordre)&lt;&gt; 12155435和   (Ordre.Ordre)&lt;&gt; 12155426和(Ordre.Ordre)&lt;&gt; 12155427和   (Ordre.Ordre)&lt;&gt; 12155604和(Ordre.Ordre)&lt;&gt; 12155420和   (Ordre.Ordre)&lt;&gt; 12155419和(Ordre.Ordre)&lt;&gt; 12155412和   (Ordre.Ordre)&lt;&gt; 12155538和(Ordre.Ordre)&lt;&gt; 12155539和   (Ordre.Ordre)&lt;&gt; 12155540和(Ordre.Ordre)&lt;&gt; 12155541和   (Ordre.Ordre)&lt;&gt; 12155542和(Ordre.Ordre)&lt;&gt; 12155543和   (Ordre.Ordre)&lt;&gt; 12155544和(Ordre.Ordre)&lt;&gt; 12155545而且   (Ordre.Ordre)&lt;&gt; 12155546和(Ordre.Ordre)&lt;&gt; 12155547和   (Ordre.Ordre)&lt;&gt; 12155442和(Ordre.Ordre)&lt;&gt; 12155440和   (Ordre.Ordre)&lt;&gt; 12155441和(Ordre.Ordre)&lt;&gt; 12155443和   (Ordre.Ordre)&lt;&gt; 12155446和(Ordre.Ordre)&lt;&gt; 12155445而且   (Ordre.Ordre)&lt;&gt; 12155448和(Ordre.Ordre)&lt;&gt; 12154726和   (Ordre.Ordre)&lt;&gt; 12154727和(Ordre.Ordre)&lt;&gt; 12154728和   (Ordre.Ordre)&lt;&gt; 12154729和(Ordre.Ordre)&lt;&gt; 12154730和   (Ordre.Ordre)&lt;&gt; 12155570和(Ordre.Ordre)&lt;&gt; 12155704和   (Ordre.Ordre)&lt;&gt; 12155935和(Ordre.Ordre)&lt;&gt; 12155936和   (Ordre.Ordre)&lt;&gt; 12155937和(Ordre.Ordre)&lt;&gt; 12155938和   (Ordre.Ordre)&lt;&gt; 12155939和(Ordre.Ordre)&lt;&gt; 12155940和   (Ordre.Ordre)&lt;&gt; 12155941和(Ordre.Ordre)&lt;&gt; 12153256和   (Ordre.Ordre)&lt;&gt; 13101358和(Ordre.Ordre)&lt;&gt; 13101309和   (Ordre.Ordre)&lt;&gt; 13212576))GROUP BY Ordre.Ordre;

4 个答案:

答案 0 :(得分:2)

您应使用AND语句,而不是所有ORIN。例如,

SELECT Ordre.Ordre, Sum(Ordre.Duree) AS SommeDeDuree 
FROM Ordre 
WHERE Ordre.Date >= #07/11/2011# 
  AND Ordre.Date <= #14/11/2011# 
  AND Ordre.Matricule In (257,516,591,...,2436,2471) 
  AND Ordre.Ordre Not In (10000477, 11146074, ... ,13101309,13212576)
GROUP BY Ordre.Ordre;

答案 1 :(得分:2)

虽然mwolfe02的解决方案是正确的,但它不能很好地扩展(就像最初的有问题的SQL)。 NOT IN表达式只允许您在达到长度限制之前在SQL字符串中加入更多值。

将值放入临时表中会更具可扩展性,但更加繁琐。这也允许您使用带有过滤器的外部联接来获取空值,这可能会更快地运行,因为NOT IN方法效率很低。例如:

SELECT Ordre.Ordre, Sum(Ordre.Duree) AS SommeDeDuree

FROM Ordre LEFT JOIN TemporaryTableName
    ON Ordre.Ordre = TemporaryTableName.Ordre

WHERE Ordre.Date >= #07/11/2011#  
  AND Ordre.Date <= #14/11/2011#  
  AND Ordre.Matricule In (257,516,591,...,2436,2471)  
  AND TemporaryTableName.Ordre IS NULL

GROUP BY Ordre.Ordre; 

答案 2 :(得分:0)

在同一SQL语句中同时引用Excel工作表和Access数据库绝不是不可能的。

Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim strExcel As String
Dim s As String
Dim i As Integer, j As Integer

strFile = "Z:\docs\LTD.mdb"

''Access and Excel 2007 / 2010 
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile

''Late binding, so no reference is needed

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

strExcel = "[Excel 12.0 Xml;HDR=YES;IMEX=2;ACCDB=YES;DATABASE=Z:\Docs\Book1.xlsm]"

strSQL = "SELECT * " _
       & "FROM New a " _
       & "INNER JOIN " & strExcel & ".[Sheet1$] b " _
       & "ON a.ID = b.ID"

rs.Open strSQL, cn, 3, 3


''Pick a suitable empty worksheet for the results

Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs

''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

答案 3 :(得分:0)

不要使用动态SQL(即动态连接值),而应考虑使用大量强类型参数创建PROCEDURE,默认为NULL。这是一个快速演示......

我已经用长手写出了参数名称,但当然可以在循环中完成。只需复制并粘贴到任何VBA代码模块中,无需引用(例如,使用Excel):

Sub AccessManyParams()

  On Error Resume Next
  Kill Environ$("temp") & "\DropMe.mdb"
  On Error GoTo 0

  Dim cat
  Set cat = CreateObject("ADOX.Catalog")

  With cat
    .Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & _
        Environ$("temp") & "\DropMe.mdb"

    With .ActiveConnection

      Dim Sql As String

      Sql = _
      "CREATE TABLE Ordre (Ordre INTEGER NOT NULL UNIQUE);"
      .Execute Sql

      Sql = _
      "INSERT INTO Ordre VALUES (55);"
      .Execute Sql

      Sql = _
      "INSERT INTO Ordre VALUES (22);"
      .Execute Sql

      Sql = vbNullString
      Sql = Sql & "CREATE PROCEDURE ChercherOrdres ( "
      Sql = Sql & "ordre_001 INTEGER = NULL, "
      Sql = Sql & "ordre_002 INTEGER = NULL, "
      Sql = Sql & "ordre_003 INTEGER = NULL, "
      Sql = Sql & "ordre_004 INTEGER = NULL, "
      Sql = Sql & "ordre_005 INTEGER = NULL, "
      Sql = Sql & "ordre_006 INTEGER = NULL, "
      Sql = Sql & "ordre_007 INTEGER = NULL, "
      Sql = Sql & "ordre_008 INTEGER = NULL, "
      Sql = Sql & "ordre_009 INTEGER = NULL, "
      Sql = Sql & "ordre_010 INTEGER = NULL, "
      Sql = Sql & "ordre_011 INTEGER = NULL, "
      Sql = Sql & "ordre_012 INTEGER = NULL, "
      Sql = Sql & "ordre_013 INTEGER = NULL, "
      Sql = Sql & "ordre_014 INTEGER = NULL, "
      Sql = Sql & "ordre_015 INTEGER = NULL, "
      Sql = Sql & "ordre_016 INTEGER = NULL, "
      Sql = Sql & "ordre_017 INTEGER = NULL, "
      Sql = Sql & "ordre_018 INTEGER = NULL, "
      Sql = Sql & "ordre_019 INTEGER = NULL, "
      Sql = Sql & "ordre_020 INTEGER = NULL, "
      Sql = Sql & "ordre_021 INTEGER = NULL, "
      Sql = Sql & "ordre_022 INTEGER = NULL, "
      Sql = Sql & "ordre_023 INTEGER = NULL, "
      Sql = Sql & "ordre_024 INTEGER = NULL, "
      Sql = Sql & "ordre_025 INTEGER = NULL, "
      Sql = Sql & "ordre_026 INTEGER = NULL, "
      Sql = Sql & "ordre_027 INTEGER = NULL, "
      Sql = Sql & "ordre_028 INTEGER = NULL, "
      Sql = Sql & "ordre_029 INTEGER = NULL, "
      Sql = Sql & "ordre_030 INTEGER = NULL, "
      Sql = Sql & "ordre_031 INTEGER = NULL, "
      Sql = Sql & "ordre_032 INTEGER = NULL, "
      Sql = Sql & "ordre_033 INTEGER = NULL, "
      Sql = Sql & "ordre_034 INTEGER = NULL, "
      Sql = Sql & "ordre_035 INTEGER = NULL, "
      Sql = Sql & "ordre_036 INTEGER = NULL, "
      Sql = Sql & "ordre_037 INTEGER = NULL, "
      Sql = Sql & "ordre_038 INTEGER = NULL, "
      Sql = Sql & "ordre_039 INTEGER = NULL, "
      Sql = Sql & "ordre_040 INTEGER = NULL, "
      Sql = Sql & "ordre_041 INTEGER = NULL, "
      Sql = Sql & "ordre_042 INTEGER = NULL, "
      Sql = Sql & "ordre_043 INTEGER = NULL, "
      Sql = Sql & "ordre_044 INTEGER = NULL, "
      Sql = Sql & "ordre_045 INTEGER = NULL, "
      Sql = Sql & "ordre_046 INTEGER = NULL, "
      Sql = Sql & "ordre_047 INTEGER = NULL, "
      Sql = Sql & "ordre_048 INTEGER = NULL, "
      Sql = Sql & "ordre_049 INTEGER = NULL, "
      Sql = Sql & "ordre_050 INTEGER = NULL, "
      Sql = Sql & "ordre_051 INTEGER = NULL, "
      Sql = Sql & "ordre_052 INTEGER = NULL, "
      Sql = Sql & "ordre_053 INTEGER = NULL, "
      Sql = Sql & "ordre_054 INTEGER = NULL, "
      Sql = Sql & "ordre_055 INTEGER = NULL, "
      Sql = Sql & "ordre_056 INTEGER = NULL, "
      Sql = Sql & "ordre_057 INTEGER = NULL, "
      Sql = Sql & "ordre_058 INTEGER = NULL, "
      Sql = Sql & "ordre_059 INTEGER = NULL, "
      Sql = Sql & "ordre_060 INTEGER = NULL, "
      Sql = Sql & "ordre_061 INTEGER = NULL, "
      Sql = Sql & "ordre_062 INTEGER = NULL, "
      Sql = Sql & "ordre_063 INTEGER = NULL, "
      Sql = Sql & "ordre_064 INTEGER = NULL, "
      Sql = Sql & "ordre_065 INTEGER = NULL, "
      Sql = Sql & "ordre_066 INTEGER = NULL, "
      Sql = Sql & "ordre_067 INTEGER = NULL, "
      Sql = Sql & "ordre_068 INTEGER = NULL, "
      Sql = Sql & "ordre_069 INTEGER = NULL, "
      Sql = Sql & "ordre_070 INTEGER = NULL, "
      Sql = Sql & "ordre_071 INTEGER = NULL, "
      Sql = Sql & "ordre_072 INTEGER = NULL, "
      Sql = Sql & "ordre_073 INTEGER = NULL, "
      Sql = Sql & "ordre_074 INTEGER = NULL, "
      Sql = Sql & "ordre_075 INTEGER = NULL, "
      Sql = Sql & "ordre_076 INTEGER = NULL, "
      Sql = Sql & "ordre_077 INTEGER = NULL, "
      Sql = Sql & "ordre_078 INTEGER = NULL, "
      Sql = Sql & "ordre_079 INTEGER = NULL, "
      Sql = Sql & "ordre_080 INTEGER = NULL, "
      Sql = Sql & "ordre_081 INTEGER = NULL, "
      Sql = Sql & "ordre_082 INTEGER = NULL, "
      Sql = Sql & "ordre_083 INTEGER = NULL, "
      Sql = Sql & "ordre_084 INTEGER = NULL, "
      Sql = Sql & "ordre_085 INTEGER = NULL, "
      Sql = Sql & "ordre_086 INTEGER = NULL, "
      Sql = Sql & "ordre_087 INTEGER = NULL, "
      Sql = Sql & "ordre_088 INTEGER = NULL, "
      Sql = Sql & "ordre_089 INTEGER = NULL, "
      Sql = Sql & "ordre_090 INTEGER = NULL, "
      Sql = Sql & "ordre_091 INTEGER = NULL, "
      Sql = Sql & "ordre_092 INTEGER = NULL, "
      Sql = Sql & "ordre_093 INTEGER = NULL, "
      Sql = Sql & "ordre_094 INTEGER = NULL, "
      Sql = Sql & "ordre_095 INTEGER = NULL, "
      Sql = Sql & "ordre_096 INTEGER = NULL, "
      Sql = Sql & "ordre_097 INTEGER = NULL, "
      Sql = Sql & "ordre_098 INTEGER = NULL, "
      Sql = Sql & "ordre_099 INTEGER = NULL, "
      Sql = Sql & "ordre_100 INTEGER = NULL, "
      Sql = Sql & "ordre_101 INTEGER = NULL, "
      Sql = Sql & "ordre_102 INTEGER = NULL, "
      Sql = Sql & "ordre_103 INTEGER = NULL, "
      Sql = Sql & "ordre_104 INTEGER = NULL, "
      Sql = Sql & "ordre_105 INTEGER = NULL, "
      Sql = Sql & "ordre_106 INTEGER = NULL, "
      Sql = Sql & "ordre_107 INTEGER = NULL, "
      Sql = Sql & "ordre_108 INTEGER = NULL, "
      Sql = Sql & "ordre_109 INTEGER = NULL, "
      Sql = Sql & "ordre_110 INTEGER = NULL, "
      Sql = Sql & "ordre_111 INTEGER = NULL, "
      Sql = Sql & "ordre_112 INTEGER = NULL, "
      Sql = Sql & "ordre_113 INTEGER = NULL, "
      Sql = Sql & "ordre_114 INTEGER = NULL, "
      Sql = Sql & "ordre_115 INTEGER = NULL, "
      Sql = Sql & "ordre_116 INTEGER = NULL, "
      Sql = Sql & "ordre_117 INTEGER = NULL, "
      Sql = Sql & "ordre_118 INTEGER = NULL, "
      Sql = Sql & "ordre_119 INTEGER = NULL, "
      Sql = Sql & "ordre_120 INTEGER = NULL, "
      Sql = Sql & "ordre_121 INTEGER = NULL, "
      Sql = Sql & "ordre_122 INTEGER = NULL, "
      Sql = Sql & "ordre_123 INTEGER = NULL, "
      Sql = Sql & "ordre_124 INTEGER = NULL, "
      Sql = Sql & "ordre_125 INTEGER = NULL, "
      Sql = Sql & "ordre_126 INTEGER = NULL, "
      Sql = Sql & "ordre_127 INTEGER = NULL, "
      Sql = Sql & "ordre_128 INTEGER = NULL, "
      Sql = Sql & "ordre_129 INTEGER = NULL, "
      Sql = Sql & "ordre_130 INTEGER = NULL, "
      Sql = Sql & "ordre_131 INTEGER = NULL, "
      Sql = Sql & "ordre_132 INTEGER = NULL, "
      Sql = Sql & "ordre_133 INTEGER = NULL, "
      Sql = Sql & "ordre_134 INTEGER = NULL, "
      Sql = Sql & "ordre_135 INTEGER = NULL, "
      Sql = Sql & "ordre_136 INTEGER = NULL, "
      Sql = Sql & "ordre_137 INTEGER = NULL, "
      Sql = Sql & "ordre_138 INTEGER = NULL, "
      Sql = Sql & "ordre_139 INTEGER = NULL, "
      Sql = Sql & "ordre_140 INTEGER = NULL, "
      Sql = Sql & "ordre_141 INTEGER = NULL, "
      Sql = Sql & "ordre_142 INTEGER = NULL, "
      Sql = Sql & "ordre_143 INTEGER = NULL, "
      Sql = Sql & "ordre_144 INTEGER = NULL, "
      Sql = Sql & "ordre_145 INTEGER = NULL, "
      Sql = Sql & "ordre_146 INTEGER = NULL, "
      Sql = Sql & "ordre_147 INTEGER = NULL, "
      Sql = Sql & "ordre_148 INTEGER = NULL, "
      Sql = Sql & "ordre_149 INTEGER = NULL, "
      Sql = Sql & "ordre_150 INTEGER = NULL) AS "
      Sql = Sql & "SELECT * FROM Ordre WHERE Ordre NOT IN ("
      Sql = Sql & "ordre_001, "
      Sql = Sql & "ordre_002, "
      Sql = Sql & "ordre_003, "
      Sql = Sql & "ordre_004, "
      Sql = Sql & "ordre_005, "
      Sql = Sql & "ordre_006, "
      Sql = Sql & "ordre_007, "
      Sql = Sql & "ordre_008, "
      Sql = Sql & "ordre_009, "
      Sql = Sql & "ordre_010, "
      Sql = Sql & "ordre_011, "
      Sql = Sql & "ordre_012, "
      Sql = Sql & "ordre_013, "
      Sql = Sql & "ordre_014, "
      Sql = Sql & "ordre_015, "
      Sql = Sql & "ordre_016, "
      Sql = Sql & "ordre_017, "
      Sql = Sql & "ordre_018, "
      Sql = Sql & "ordre_019, "
      Sql = Sql & "ordre_020, "
      Sql = Sql & "ordre_021, "
      Sql = Sql & "ordre_022, "
      Sql = Sql & "ordre_023, "
      Sql = Sql & "ordre_024, "
      Sql = Sql & "ordre_025, "
      Sql = Sql & "ordre_026, "
      Sql = Sql & "ordre_027, "
      Sql = Sql & "ordre_028, "
      Sql = Sql & "ordre_029, "
      Sql = Sql & "ordre_030, "
      Sql = Sql & "ordre_031, "
      Sql = Sql & "ordre_032, "
      Sql = Sql & "ordre_033, "
      Sql = Sql & "ordre_034, "
      Sql = Sql & "ordre_035, "
      Sql = Sql & "ordre_036, "
      Sql = Sql & "ordre_037, "
      Sql = Sql & "ordre_038, "
      Sql = Sql & "ordre_039, "
      Sql = Sql & "ordre_040, "
      Sql = Sql & "ordre_041, "
      Sql = Sql & "ordre_042, "
      Sql = Sql & "ordre_043, "
      Sql = Sql & "ordre_044, "
      Sql = Sql & "ordre_045, "
      Sql = Sql & "ordre_046, "
      Sql = Sql & "ordre_047, "
      Sql = Sql & "ordre_048, "
      Sql = Sql & "ordre_049, "
      Sql = Sql & "ordre_050, "
      Sql = Sql & "ordre_051, "
      Sql = Sql & "ordre_052, "
      Sql = Sql & "ordre_053, "
      Sql = Sql & "ordre_054, "
      Sql = Sql & "ordre_055, "
      Sql = Sql & "ordre_056, "
      Sql = Sql & "ordre_057, "
      Sql = Sql & "ordre_058, "
      Sql = Sql & "ordre_059, "
      Sql = Sql & "ordre_060, "
      Sql = Sql & "ordre_061, "
      Sql = Sql & "ordre_062, "
      Sql = Sql & "ordre_063, "
      Sql = Sql & "ordre_064, "
      Sql = Sql & "ordre_065, "
      Sql = Sql & "ordre_066, "
      Sql = Sql & "ordre_067, "
      Sql = Sql & "ordre_068, "
      Sql = Sql & "ordre_069, "
      Sql = Sql & "ordre_070, "
      Sql = Sql & "ordre_071, "
      Sql = Sql & "ordre_072, "
      Sql = Sql & "ordre_073, "
      Sql = Sql & "ordre_074, "
      Sql = Sql & "ordre_075, "
      Sql = Sql & "ordre_076, "
      Sql = Sql & "ordre_077, "
      Sql = Sql & "ordre_078, "
      Sql = Sql & "ordre_079, "
      Sql = Sql & "ordre_080, "
      Sql = Sql & "ordre_081, "
      Sql = Sql & "ordre_082, "
      Sql = Sql & "ordre_083, "
      Sql = Sql & "ordre_084, "
      Sql = Sql & "ordre_085, "
      Sql = Sql & "ordre_086, "
      Sql = Sql & "ordre_087, "
      Sql = Sql & "ordre_088, "
      Sql = Sql & "ordre_089, "
      Sql = Sql & "ordre_090, "
      Sql = Sql & "ordre_091, "
      Sql = Sql & "ordre_092, "
      Sql = Sql & "ordre_093, "
      Sql = Sql & "ordre_094, "
      Sql = Sql & "ordre_095, "
      Sql = Sql & "ordre_096, "
      Sql = Sql & "ordre_097, "
      Sql = Sql & "ordre_098, "
      Sql = Sql & "ordre_099, "
      Sql = Sql & "ordre_100, "
      Sql = Sql & "ordre_101, "
      Sql = Sql & "ordre_102, "
      Sql = Sql & "ordre_103, "
      Sql = Sql & "ordre_104, "
      Sql = Sql & "ordre_105, "
      Sql = Sql & "ordre_106, "
      Sql = Sql & "ordre_107, "
      Sql = Sql & "ordre_108, "
      Sql = Sql & "ordre_109, "
      Sql = Sql & "ordre_110, "
      Sql = Sql & "ordre_111, "
      Sql = Sql & "ordre_112, "
      Sql = Sql & "ordre_113, "
      Sql = Sql & "ordre_114, "
      Sql = Sql & "ordre_115, "
      Sql = Sql & "ordre_116, "
      Sql = Sql & "ordre_117, "
      Sql = Sql & "ordre_118, "
      Sql = Sql & "ordre_119, "
      Sql = Sql & "ordre_120, "
      Sql = Sql & "ordre_121, "
      Sql = Sql & "ordre_122, "
      Sql = Sql & "ordre_123, "
      Sql = Sql & "ordre_124, "
      Sql = Sql & "ordre_125, "
      Sql = Sql & "ordre_126, "
      Sql = Sql & "ordre_127, "
      Sql = Sql & "ordre_128, "
      Sql = Sql & "ordre_129, "
      Sql = Sql & "ordre_130, "
      Sql = Sql & "ordre_131, "
      Sql = Sql & "ordre_132, "
      Sql = Sql & "ordre_133, "
      Sql = Sql & "ordre_134, "
      Sql = Sql & "ordre_135, "
      Sql = Sql & "ordre_136, "
      Sql = Sql & "ordre_137, "
      Sql = Sql & "ordre_138, "
      Sql = Sql & "ordre_139, "
      Sql = Sql & "ordre_140, "
      Sql = Sql & "ordre_141, "
      Sql = Sql & "ordre_142, "
      Sql = Sql & "ordre_143, "
      Sql = Sql & "ordre_144, "
      Sql = Sql & "ordre_145, "
      Sql = Sql & "ordre_146, "
      Sql = Sql & "ordre_147, "
      Sql = Sql & "ordre_148, "
      Sql = Sql & "ordre_149, "
      Sql = Sql & "ordre_150);"

      .Execute Sql
    End With

    Dim cmd
    Set cmd = CreateObject("ADODB.Command")
    Set cmd.ActiveConnection = .ActiveConnection

    With cmd
      .CommandType = adCmdStoredProc
      .CommandText = "ChercherOrdres"
      .Parameters.Append .CreateParameter("ordre_091", adInteger, , , "22")
      .Parameters.Append .CreateParameter("ordre_147", adInteger, , , "-99")

      Dim rs
      Set rs = .Execute
      MsgBox rs.GetString

    End With
    Set .ActiveConnection = Nothing
  End With
End Sub