⑴ vb sql 查询
select
distinct
a,b,c,d
from
abc
order
by
c
desc
distinct
关键字
是取唯一值
整句意思是
查询
在表abc中按c由大到小排序的
a
b
c
d字段,然后取唯一值
如果你用的是sql
server的话也可以用
top关键字
top
1就是显示前面1个
top
2
就是两行
select
top
1
a,b,c,d
from
abc
order
by
c
desc
哦,忘记名字了,有两种方法,一是按名字先分组,然后在排序,另一种就是直接按两个排序
1.select
top
1
a,b,c,d
from
abc
group
by
a
order
by
c
desc
select
distinct
a,b,c,d
from
abc
group
by
a
order
by
c
desc
2.select
top
1
a,b,c,d
from
abc
order
by
a,c
desc
select
distinct
a,b,c,d
from
abc
order
by
a,c
desc
⑵ SQL vb select 多条件查询
注意关于日期的条件书写格式:
我们都知道,对于字符串,用单引号,而对于日期/时间类型,用井号!!!!!!
而且,你的Where字句也不能被Order 字句分隔开成两部分的呀??????
要这样:
"select * from 加油信息表 where 日期 between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "# and 卡号 = '"& text1.text & "' order by 日期"
注意:四个"#"号代替了原来的单引号!!!!
注意:后面 卡号 的条件与前面日期条件连接在一起的!!!!!!
最后是 Order By ......
⑶ VB 中SQL查询语句中的查询条件有什么语法格式 where ……
field1 like ’%value1%’
field1是字段名,like '%value1%'表示包含"value1",其中%是通配符,表示一个或多个字符。
需要说明的是,如果你用的是Access数据库,貌似等效于%的通配符是*
"+"是字符串运算符,如“Abc”+“123”=“Abc123".
⑷ vb里用SQL的多条件查询,请教
什么意思7各控件存的是字段名称?然后要求查询出这7各字段均不为空的所有数据?
假设字段名称存在Text1.Text,Text2.Text,Text3.Text,Text4.Text,Text5.Text,Text6.Text,Text7.Text
DimsqlStrasString
sqlStr="Select*frommyTablewhere"&Text1.Text&"isnotnulland"&_
sqlStr=sqlStr&Text2.Text&"isnotnulland"&_
sqlStr=sqlStr&Text3.Text&"isnotnulland"&_
sqlStr=sqlStr&Text4.Text&"isnotnulland"&_
sqlStr=sqlStr&Text5.Text&"isnotnulland"&_
sqlStr=sqlStr&Text6.Text&"isnotnulland"&_
sqlStr=sqlStr&Text7.Text&"isnotnull"
⑸ vb中如何写sql查询条件
TmpSource = "SELECT l.MsgId as 编号,l.Mobile as 号码,l.Send_datetime as 发送时间,l.Sendtype as 发送类型,l.SendResult as 发送结果,l.MsgContent as 短信内容" _
+ " FROM SendHistory l WHERE Send_datetime like %" _
+ 月 + "%"
补充:
TmpSource = "SELECT l.Send_datetime as 发送时间,l.MsgContent as 短信内容" _
+ " FROM SendHistory l WHERE Send_datetime like +" _
+ " '" + s + "%' And Send_datetime > '" + ss + "' And Send_datetime < '" + sover + "'"
你的引号位置用错了
⑹ vb6.0连接sql sever中用条件实现查找功能该怎么写
假设多个文本框输入不同的查询条件,如果只支持单个条件查询,需要单选框Option:
str1 = "select * from ... where 1=1"
if option1.value then '字段1
str1 = str1 & "字段1=" & Text1.Text
endif
if option2.value then
str1= str1 & "字段2=" & Text2.texxt
endif
如果支持多条件查询:
str1 = "select * from ... where 字段1=" & text1.text & " and 字段2=" & text2.text "...
rs.open str1
显示数据最方便的当然是网格控件了,比如VB自带的DataGrid,MSFlexGrid。当然也可以用多个文本框来显示,每个文本框对应一个字段。
对于简单数据,也可以用多行文本框或者列表框等等,只要输出时把字段的值组合以下就可以了:
do until rs.eof
Text1.text =Text1.text & rs(0) & " " rs(1) ... & vbcrlf
loop
⑺ vb中如何写sql查询条件
sql="select
*
from
(表格名字)
where
id='"
&
text1.text
&
"'
and
name='"
&
text2.text
&
"'
and
age="'
&
text3.text
&
"'
order
by
id
asc"
order
by
id
asc
这句意思是按id升序排列,可写可不写。
⑻ vb SQL多条件查询
举例说明,实现如下多条件查询:
Private Sub Command1_Click() Dim jsql jsql = ""
Dim smyregion As String If Check1.Value = 1 Then
jsql = "图书名称 like '%" + Text1.Text + "%'" End If
If Check2.Value = 1 Then If jsql = "" Then
jsql = "作者姓名 like'%" + Text2.Text + "%'" Else
jsql = jsql & "and 作者姓名 like'%" + Text2.Text + "%'" End If End If
If Check3.Value = 1 Then If jsql = "" Then
jsql = "出版社名称 like'%" + Text3.Text + "%'" Else
jsql = jsql & "and 出版社名称 like '%" + Text3.Text + "%'" End If End If
If Check4.Value = 1 Then If jsql = "" Then
jsql = "出版时间 like '%" + Text4.Text + "%'" Else
jsql = jsql & "and 出版时间 like '%" + Text3.Text + "%'" End If End If
If Check5.Value = 1 Then If jsql = "" Then
jsql = "图书类别 like '%" + Text5.Text + "%'"
Else
jsql = jsql & "and 图书类别 like '%" + Text5.Text + "%'" End If End If
If jsql = "" Then
MsgBox "请选择查询条件!", vbInformation, "图书音像管理系统" Exit Sub Else
Adodc1.RecordSource = "select * from book where " & jsql Adodc1.Refresh End If
If Adodc1.Recordset.RecordCount > 0 Then Set DataGrid1.DataSource = Adodc1 End If End Sub
Private Sub Command2_Click() Unload Me End Sub
⑼ VB SQL 多条件查询
先选好条件,然后再来按查询按钮实现查询功能,只是一种很普通的查询功能。
其实你可以通过用多个combo控件来实现条件筛选,然后在每一个combo的change事件里写上相同的查询功能的代码(最好是一个自编的函数,这样,你每一次选择条件后,马上就可以看到筛选结果,这样是比较人性化的,而实际止大多的开发人员也是这样做
的。,不明白的话你再问我吧。
⑽ vb sql 多条件 查找
text1.text 地区
text2.text 时间
dim place,time as string
place = text1.text
time = text2.text
sql = "select * from table where place='" & place &"' and time='" & time &"'"