vb select 多条件查询语句该怎么实现

2025-01-19 17:01:33
推荐回答(2个)
回答1:

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

测试可用。

回答2:

用AND连起来就是了

"select * from sb_report where start_t between '" & time_x & "'and '" & time_y & "' " And sb_name = '" & no &"' " &order by start_t