日期:2014-05-18  浏览次数:20608 次

●●●菜鳥求一個JSP下簡單的sql語句 請大家幫忙●●●
我有三個條件
1●GuanLiNo  
2●Projectname  
3●PartNo
●PartPress   為數據庫名
●現在需要條件2單獨實現。1,2組合。2,3組合。1,2,3組合。形成一條SQL語句該怎麼寫?
下面這條是我自己寫的只能實現   1,2組合。2,3組合。現在就是要求全部組合和2單獨實現的情況該怎麼寫???
●sql= "select   *   from     PartPress   where  
(GuanLiNo   =   ' "+GuanLiNo+ " '   and   Projectname   =   ' "+Projectname+ " 'and   PartNo= ' "+PartNo+ " ')   or  
(GuanLiNo   =   ' "+GuanLiNo+ " '   and   Projectname   =   ' "+Projectname+ " ')   or   (GuanLiNo   =   ' "+GuanLiNo+ " '   and   PartNo= ' "+PartNo+ " ')   or  
(GuanLiNo   =   ' "+GuanLiNo+ " '   and   Projectname   =   ' "+Projectname+ " '   and   PartNo= ' "+PartNo+ " ') "   ;
祝大家
╭╮__╭╭╭╭╭__╭╮  

│              │   ╭————————╮  

│              │   │       恭喜發財!!       │  

│ ● ╭———╮ ●     │   │                       │  

│≡  │● ●│  ≡      ╭╮│    桃花運來!!         │

│          ╰———╯          │o╰╯│          ^O^               │

╰——┬○————┬—○╯   ╰————————╯


------解决方案--------------------
说真的,不知道你说什么。
帮忙顶
------解决方案--------------------
还繁体。。。。。。。。大哥,我看的累啊
------解决方案--------------------
方法重载 or if-if-if
------解决方案--------------------
http://community.csdn.net/Expert/topic/5391/5391940.xml?temp=.2519495
------解决方案--------------------
String sql= "select * from PartPress where 1=1 ";
if(GuanLiNo !=null)
{
sql=sql+ "and GuanLiNo= ' "+GuanLiNo+ " ' ";
}
if(Projectname!=null)
{
sql=sql+ "and Projectname= '+Projectname+ " ' ";
}
if(PartNo!=null)
{
sql=sql+ "and PartNo= ' "+PartNo+ ", ";
}
实现了GuanLiNo ,Projectname,PartNo查询条件的任意组合了.