Dim op_StartTime As String 
    Dim op_EndTime As String 
    Dim sqlfind As String 
    Dim sqlfind1 As String 
    op_StartTime = Format(DTPS_op.Value, "YYYY-MM-DD") & " 00:00:00" 
    op_EndTime = Format(DTPE_op.Value, "YYYY-MM-DD") & " 23:59:59" 
    sqlfind1 = "" 
    If Not (Combo1.Text = "" And Combo2.Text = "" And Combo3.Text = "") Then 
        If Combo1.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作车间='" & Combo1.Text & "')" 
        If Combo2.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作系统='" & Combo2.Text & "')" 
        If Combo3.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作设备='" & Combo3.Text & "')" 
    End If 
    sqlfind = "SELECT 序号,(SELECT COUNT(*) FROM operation a WHERE a.序号 <= operation.序号 and  (操作时间>='" _ 
        & op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & " ) AS ID,操作车间,操作系统," _ 
        & "操作设备,操作描述 from operation where (操作时间>='" _ 
        & op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & "order by id"     表(operation) 字段(序号,操作时间,操作车间,操作系统,操作设备,操作描述) 
  查询条件 开始时间 结束时间 操作车间 操作系统 操作设备。 
   为什么我这么写不能查询呢?请高手指点。 
 
 

解决方案 »

  1.   

    SELECT 序号
        ,(SELECT COUNT(*) 
            FROM operation a 
            WHERE a.序号 <= operation.序号 
            and  (操作时间>='t1') 
            and (操作时间 <='t2')  
            and (操作车间='c1') 
            and (操作系统='c2') 
            and (操作设备='c3') 
            ) AS ID
        ,操作车间
        ,操作系统
        ,操作设备
        ,操作描述 
    from operation 
    where (操作时间>='t1') 
    and (操作时间 <='t2')  
    and (操作车间='c1') 
    and (操作系统='c2') 
    and (操作设备='c3')
    order by id循环引用,意图是什么?
      

  2.   

    这样看看SELECT 序号
        ,(SELECT COUNT(*) 
            FROM operation a 
            WHERE a.序号 <= b.序号 
            and  (操作时间>='t1') 
            and (操作时间 <='t2')  
            and (操作车间='c1') 
            and (操作系统='c2') 
            and (操作设备='c3') 
            ) AS ID
        ,操作车间
        ,操作系统
        ,操作设备
        ,操作描述 
    from operation as b
    where (操作时间>='t1') 
    and (操作时间 <='t2')  
    and (操作车间='c1') 
    and (操作系统='c2') 
    and (操作设备='c3')
    order by id
      

  3.   


    我只是看你的sql,没看程序
      

  4.   

    看看这样如何
        Dim op_StartTime As String
        Dim op_EndTime As String
        Dim sqlfind As String
        Dim sqlfind1 As String
        op_StartTime = Format(DTPS_op.Value, "YYYY-MM-DD") & " 00:00:00"
        op_EndTime = Format(DTPE_op.Value, "YYYY-MM-DD") & " 23:59:59"
        sqlfind1 = ""
        If Not (Combo1.Text = "" And Combo2.Text = "" And Combo3.Text = "") Then
            If Combo1.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作车间='" & Combo1.Text & "')"
            If Combo2.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作系统='" & Combo2.Text & "')"
            If Combo3.Text <> "" Then sqlfind1 = sqlfind1 & " and (操作设备='" & Combo3.Text & "')"
        End If
        sqlfind = "SELECT 序号,(SELECT COUNT(*) FROM operation a WHERE a.序号 <= b.序号 and  (操作时间>='" _
            & op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & " ) AS ID,操作车间,操作系统," _
            & "操作设备,操作描述 from operation as b where (操作时间>='" _
            & op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & "order by id"