当前位置: 技术问答>java相关
一个查询数据的问题?请各位大虾帮忙!
来源: 互联网 发布时间:2017-04-17
本文导语: 有下面一些文本框: aa: bb: cc: dd: ee: 我想这样查询:如果aa,bb里面有数据,那么查询的条件是根据aa,bb查询,如下: String sql="select * from ajgl where aa like '%"+aa+"%' and bb like '%"+bb"%'"; 如果bb,cc,ee里面有数据,那么...
有下面一些文本框:
aa:
bb:
cc:
dd:
ee:
我想这样查询:如果aa,bb里面有数据,那么查询的条件是根据aa,bb查询,如下:
String sql="select * from ajgl where aa like '%"+aa+"%' and bb like '%"+bb"%'";
如果bb,cc,ee里面有数据,那么查询的条件是根据bb,cc,ee查询,如下
String sql="select * from ajgl where bb like '%"+bb+"%' and cc like '%"+cc"%' and ee like '%"+ee+"%'";
如果所有的文本框里都没有数据的话,查询的条件是:
String sql="select * from ajgl";
aa:
bb:
cc:
dd:
ee:
我想这样查询:如果aa,bb里面有数据,那么查询的条件是根据aa,bb查询,如下:
String sql="select * from ajgl where aa like '%"+aa+"%' and bb like '%"+bb"%'";
如果bb,cc,ee里面有数据,那么查询的条件是根据bb,cc,ee查询,如下
String sql="select * from ajgl where bb like '%"+bb+"%' and cc like '%"+cc"%' and ee like '%"+ee+"%'";
如果所有的文本框里都没有数据的话,查询的条件是:
String sql="select * from ajgl";
|
最简单的办法
sql1="1=1"
if(aa!=""){
sql1=sql+" and aa like '%"+aa+"%'";
}
if(bb!=""){
sql1=sql1+" and bb like '%"+bb+"%'";
}
sql="select * from ajgl where "+sql1
sql1="1=1"
if(aa!=""){
sql1=sql+" and aa like '%"+aa+"%'";
}
if(bb!=""){
sql1=sql1+" and bb like '%"+bb+"%'";
}
sql="select * from ajgl where "+sql1
|
function condition_build()
dim strwhere
dim strval,strcom
strwhere = ""
if Request("zd_1") "" then
strcom = Trim(request("de_1"))
if strcom = "like" then
strval = "'%"&Request("val_1")&"%'"
else
strval = "'"&Request("val_1")&"'"
end if
strwhere = Request("left_c_1")&Request("zd_1")&Request("de_1")&strval&Request("right_1")
end if
'Response.Write strWhere
if Request("zd_2") "" then
strcom = Trim(request("de_2"))
if strcom = "like" then
strval = "'%"&Request("val_2")&"%'"
else
strval = "'"&Request("val_2")&"'"
end if
strwhere = strwhere&Request("left_l_2")&Request("left_c_2")&Request("zd_2")&Request("de_2")&strval&Request("right_2")
end if
'Response.Write strWhere
if Request("zd_3") "" then
strcom = Trim(request("de_3"))
if strcom = "like" then
strval = "'%"&Request("val_3")&"%'"
else
strval = "'"&Request("val_3")&"'"
end if
strwhere = strwhere&Request("left_l_3")&Request("left_c_3")&Request("zd_3")&Request("de_3")&strval&Request("right_3")
end if
'Response.Write strWhere
if Request("zd_4") "" then
strcom = Trim(request("de_4"))
if strcom = "like" then
strval = "'%"&Request("val_4")&"%'"
else
strval = "'"&Request("val_4")&"'"
end if
strwhere = strwhere&Request("left_l_4")&Request("left_c_4")&Request("zd_4")&Request("de_4")&strval&Request("right_4")
end if
'Response.Write strWhere
if Request("zd_5") "" then
strcom = Trim(request("de_5"))
if strcom = "like" then
strval = "'%"&Request("val_5")&"%'"
else
strval = "'"&Request("val_5")&"'"
end if
strwhere = strwhere&Request("left_l_5")&Request("left_c_5")&Request("zd_5")&Request("de_5")&strval&Request("right_5")
end if
'Response.Write "where:"
'Response.Write strWhere
'Response.Write ":end where"
'Response.Write "
"
strfilter = strwhere
Set condition_build=strwhere
end function
dim strwhere
dim strval,strcom
strwhere = ""
if Request("zd_1") "" then
strcom = Trim(request("de_1"))
if strcom = "like" then
strval = "'%"&Request("val_1")&"%'"
else
strval = "'"&Request("val_1")&"'"
end if
strwhere = Request("left_c_1")&Request("zd_1")&Request("de_1")&strval&Request("right_1")
end if
'Response.Write strWhere
if Request("zd_2") "" then
strcom = Trim(request("de_2"))
if strcom = "like" then
strval = "'%"&Request("val_2")&"%'"
else
strval = "'"&Request("val_2")&"'"
end if
strwhere = strwhere&Request("left_l_2")&Request("left_c_2")&Request("zd_2")&Request("de_2")&strval&Request("right_2")
end if
'Response.Write strWhere
if Request("zd_3") "" then
strcom = Trim(request("de_3"))
if strcom = "like" then
strval = "'%"&Request("val_3")&"%'"
else
strval = "'"&Request("val_3")&"'"
end if
strwhere = strwhere&Request("left_l_3")&Request("left_c_3")&Request("zd_3")&Request("de_3")&strval&Request("right_3")
end if
'Response.Write strWhere
if Request("zd_4") "" then
strcom = Trim(request("de_4"))
if strcom = "like" then
strval = "'%"&Request("val_4")&"%'"
else
strval = "'"&Request("val_4")&"'"
end if
strwhere = strwhere&Request("left_l_4")&Request("left_c_4")&Request("zd_4")&Request("de_4")&strval&Request("right_4")
end if
'Response.Write strWhere
if Request("zd_5") "" then
strcom = Trim(request("de_5"))
if strcom = "like" then
strval = "'%"&Request("val_5")&"%'"
else
strval = "'"&Request("val_5")&"'"
end if
strwhere = strwhere&Request("left_l_5")&Request("left_c_5")&Request("zd_5")&Request("de_5")&strval&Request("right_5")
end if
'Response.Write "where:"
'Response.Write strWhere
'Response.Write ":end where"
'Response.Write "
"
strfilter = strwhere
Set condition_build=strwhere
end function