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

这样的查询该如何写代码

2012-02-10 
这样的查询该怎么写代码条件一:温度上限()温度下限()条件二:压力上限()压力下限()条件三:流量上限()流量下

这样的查询该怎么写代码
条件一:温度上限()   温度下限()
条件二:压力上限()   压力下限()
条件三:流量上限()   流量下限()
条件四:datacombo  
四个条件可以单独,两两,三个或者全选查询
这样的代码该怎么写?


[解决办法]
用VBA动态生成查询SQL串。

dim strSQL as String

strSQL= "select * from 表名 where 1=1 "

if not isnull(int温度上限)
strSQL= " and 温度 <= " & int温度上限

if not isnull(int温度下限)
strSQL= " and 温度> = " & int温度下限


if not isnull(int压力上限)
strSQL= " and 压力 <= " & int压力上限

...

[解决办法]
1、请到相应的语言版块去问吧;
2、VB应该与VBA相差不大,VBA是VB的子集
dim strSQL as String

strSQL= "select * from 表名 where 1=1 "

if not isnull(int温度上限)
strSQL= " and 温度 <= " & int温度上限

if not isnull(int温度下限)
strSQL= " and 温度> = " & int温度下限


if not isnull(int压力上限)
strSQL= " and 压力 <= " & int压力上限
用变量进行累加
[解决办法]
dim strSQL as String

strSQL= "select * from 表名 where 1=1 "

if not isnull(int温度上限)
strSQL= " and 温度 <= " & int温度上限

if not isnull(int温度下限)
strSQL= " and 温度> = " & int温度下限


if not isnull(int压力上限)
strSQL= " and 压力 <= " & int压力上限

热点排行