您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



4个以上的变量筛选查询要怎么做


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


4个以上的变量筛选查询要怎么做
发表于:2007-01-09 16:14:24 楼主
dim   sql   as   string,   sid   as   string,   sname   as   string
sql   =   "select     *   from   temp1   where   "
sid   =   text1.text          
sname   =   text2.text
if   len(sid)   =   0   and   len(sname)   =   0   then   exit   sub
if   len(sid)   then   sql   =   sql   &   "id   =   ' "   &   sid   &   " '   "
if   len(sname)   then
        if   len(sid)   then   sql   =   sql   &   "and   "
        sql   =   sql   &   "name   like   '% "   &   sname   &   "% ' "
end   if

这是两个的变量筛选查询,有4个以上更多的变量时用同样的方法变的很复杂,要用什么方式来做,比较容易理解一点
发表于:2007-01-09 17:26:091楼 得分:0
dim   tmp1   as   string
dim   tmp2   as   string
dim   tmp3   as   string
dim   strsql   as   string
if   trim(text1.text)= " "   then
        tmp1= " "
else
        tmp1= "   and   字段1= ' "&   trim(text1.text)   & " ' "
end   if
if   trim(text2.text)= " "   then
        tmp2= " "
else
        tmp2= "   and   字段2= ' "&   trim(text2.text)   & " ' "
end   if
if   trim(text3.text)= " "   then
        tmp3= " "
else
        tmp3= "   and   字段3= ' "&   trim(text3.text)   & " ' "
end   if

strsql= "   select   *   from   tablename   where   1=1   "   &   tmp1   &   tmp2   &   tmp3
发表于:2007-01-09 17:28:522楼 得分:0
关注


快速检索

最新资讯
热门点击