日期:2014-05-16  浏览次数:20881 次

这样的查询该怎么写代码
条件一:温度上限()   温度下限()
条件二:压力上限()   压力下限()
条件三:流量上限()   流量下限()
条件四: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压力上限