数据库查询问题
Dim op_StartTime As StringDim 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) 字段(序号,操作时间,操作车间,操作系统,操作设备,操作描述)
查询条件 开始时间 结束时间 操作车间 操作系统 操作设备。
为什么我这么写不能查询呢?请高手指点。 --------------------编程问答--------------------
FROM operation a WHERE a.序号 <= operation.序号 and (操作时间>='" _
& op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & " ) AS ID,操作车间,操作系统," _
& "操作设备,操作描述 from operation where (操作时间>='" _
--------------------编程问答-------------------- 噢,看错了 - - 汗 你嵌套查询了 --------------------编程问答-------------------- 谢谢楼上,有没有高手帮助解决下 急 --------------------编程问答--------------------
SELECT COUNT(*) FROM operation a WHERE a.序号 <= operation.序号 and (操作时间>='" _
& op_StartTime & "') and (操作时间 <='" & op_EndTime & "') " & sqlfind1 & " ) AS ID
你要求,ID是根据某条件查出来的固定值,一列下来都是一个值?
按说类似这样写是没问题的:
select * ,(select count(*) from dbo.ac) as ac_id from dbo.ac order by ac_id --------------------编程问答-------------------- 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"
Debug.Print' 在数据库中执行看看 --------------------编程问答-------------------- a.序号 <= operation.序号
这个逻辑有问题
lz的意图说一下 --------------------编程问答-------------------- 就是想根据时间段 操作车间 操作系统 操作设备 查询操作记录 --------------------编程问答-------------------- 这样看看
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"
补充:VB , 基础类