首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么进行多字段的查询.有关问题解决立即给分

2012-01-16 
如何进行多字段的查询.在线等.问题解决立即给分我的表中有三个字段日期,产品名称,销售员,我现在想实现动态

如何进行多字段的查询.在线等.问题解决立即给分
我的表中有三个字段
日期,产品名称,销售员,

我现在想实现动态查询的效果,就是我也许查询日期,也许查询日期和产品名称,也许三个字段都查,就是不一定选中哪个字段进行查询,也不一定选中几个,在sql语句中怎样写呢

[解决办法]
dim tmp_date as string
dim tmp_name as string
dim tmp_person as string
dim strsql as string
if text1.text= " " then '假设text1控件用于输入日期
tmp_date= " "
else
tmp_date= " and 日期= ' "& text1.text & " ' "
end if
if text2.text= " " then '假设text2控件用于输入产品名称
tmp_name= " "
else
tmp_name= " and 产品名称= ' "& text2.text & " ' "
end if
if text3.text= " " then '假设text3控件用于输入销售员
tmp_person= " "
else
tmp_person= " and 销售员= ' "& text3.text & " ' "
end if

'构造SQL查询语句
strsql= " select * from tablename where 1=1 " & tmp_date & tmp_name & tmp_person


[解决办法]
1=1 是为了给它一个必然成立的条件,要不不知道那个在接在where 后面,还得专门去掉“and”,但现在这样就不用了!
Leftie 很聪明!

热点排行