vb select 多条件查询语句该怎么实现
我想做个根据选择时间范围、电机编号、再进行对start_t字段按照时间先后进行排序,我单个条件查询都没有问题了,但是用And来连接3个条件不正确,具体该怎么写,请哪位大侠...
我想做个根据选择时间范围、电机编号、再进行对start_t字段按照时间先后进行排序,我单个条件查询都没有问题了,但是用And 来连接3个条件不正确,具体该怎么写,请哪位大侠帮忙,谢谢。
其中:
时间范围查询:sql = "select * from sb_report where start_t between '" & time_x & "'and '" & time_y & "' "
电机编号查询:sql = "select * from sb_report where sb_name = '" & no &"' " 其中no为电机编号。
按照时间排序:sql = "select * from sb_report order by start_t 展开
其中:
时间范围查询:sql = "select * from sb_report where start_t between '" & time_x & "'and '" & time_y & "' "
电机编号查询:sql = "select * from sb_report where sb_name = '" & no &"' " 其中no为电机编号。
按照时间排序:sql = "select * from sb_report order by start_t 展开
展开全部
Private Sub cmdSearchGuest_Click() '快速查询
Dim sql As String
Dim cBranchID As String
Dim cBranchName As String
Dim cBranchTel As String
sql = "SELECT 客户编号,客户名称,联系地址,联系电话,邮箱,创建日期,备注 FROM 客户信息 where 1=1"
If txtSearchGuestNo.Text <> "" Then sql = sql & " and 客户编号 like '%" & txtSearchGuestNo.Text & "%'" '客户编号
If txtSearchGuestName.Text <> "" Then sql = sql & " and 客户名称 like '%" & txtSearchGuestName.Text & "%'" '客户名称
If txtSearchAddress.Text <> "" Then sql = sql & " and 联系地址 like '%" & txtSearchAddress.Text & "%'" '电话
If txtSearchTel.Text <> "" Then sql = sql & " and 联系电话 like '%" & txtSearchTel.Text & "%'" '电话
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub
测试可用。
Dim sql As String
Dim cBranchID As String
Dim cBranchName As String
Dim cBranchTel As String
sql = "SELECT 客户编号,客户名称,联系地址,联系电话,邮箱,创建日期,备注 FROM 客户信息 where 1=1"
If txtSearchGuestNo.Text <> "" Then sql = sql & " and 客户编号 like '%" & txtSearchGuestNo.Text & "%'" '客户编号
If txtSearchGuestName.Text <> "" Then sql = sql & " and 客户名称 like '%" & txtSearchGuestName.Text & "%'" '客户名称
If txtSearchAddress.Text <> "" Then sql = sql & " and 联系地址 like '%" & txtSearchAddress.Text & "%'" '电话
If txtSearchTel.Text <> "" Then sql = sql & " and 联系电话 like '%" & txtSearchTel.Text & "%'" '电话
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub
测试可用。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询