例如,有3个以上的下拉列表可以分别选择,“出版时间”、“出版社”、“类别”、....动作是查询新书,下拉列表的组合是随机的,可以是一个,可以是全部,由查询的人自己决定,这样的查询如何写呢?主要是想看看不同的算法,请高手不吝施教,谢谢!

解决方案 »

  1.   

    sqlstr:='select fields from table where 1=1'
    if 选“出版时间” then
    sqlstr:=sqlstr+'and 出版时间='+出版时间;
    if 选“出版社” then
    sqlstr:=sqlstr+'and 出版社='+出版社
    if 选“类别” then
    sqlstr:=sqlstr+' and 类别='+类别
      

  2.   

    sql:='select * from table where 1=1 ';
    if combobox1.text<>'' then
      sql:=sql+' and 出版时间='''+ combobox1.text+'''';
    if combobox2.text<>'' then
      sql:=sql+' and 出版社='''+ combobox2.text+'''';
    if combobox3.txt<>'' then
      sql:=sql+' and 类别='''+ combobox3.text+'''';
    ..
      

  3.   

    http://expert.csdn.net/Expert/topic/1855/1855559.xml?temp=.0741846