⑴ 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 &"'"