('"+sqla+"')------ 这两个单引号是多余的

解决方案 »

  1.   

    你把sqla和sql2显示出来看一下就知道问题在哪里了,应该是sql2引用sqla时出错...
      

  2.   

    你把sql1的where 1=1去掉好了
      

  3.   

    WIPROD,WISEQ,WITOOL 合在一起才是唯一。我后面加上and y.WIPROD is null 。是否正确?还是要加上and y.WIPROD is null  and y.WISEQ  is null  ??
      

  4.   

    原来要把 sql1.Append("order by WIPROD desc ");
    放在sql1下面才行。但是下面的if条件成立的时候,先加order by  再加and 语句 就有问题了。难道要上下都放一个order by?
      

  5.   

    sql2 放在上面就不对,他已经获得了sql的值,后面附加的sql1部分内容sql2都得不到,只是sql1自己得到了
      

  6.   

    试改下:
    StringBuilder   sql1   =   new StringBuilder( "select top "+PageSize*CurrentPage+" WIPROD,WISEQ,WITOOL from I_ITH where 1=1 "); 
    string sqla=sql1.ToString();StringBuilder   sql2   =   new StringBuilder( "Select Top " + PageSize + "  x.* from I_ITH x left join  (");
          
                if(TextBox1.Text != "" & TextBox2.Text != "" )               { 
                    sql1.Append( " and WITOOL between '"+a+"' and '"+b+"'  ");
                    sql2.Append( " and x.WITOOL between '"+a+"' and  '"+b+"'  ");
            
                }             if(TextBox3.Text != "" & TextBox4.Text != "")               {
                    sql1.Append(" and WISEQ between '"+c+"'  and  '"+d+"'");
                    sql2.Append(" and x.WISEQ between '"+c+"'  and  '"+d+"'");
                }
                if(TextBox5.Text != "" & TextBox6.Text != "")               {
                    sql1.Append(" and WIPROD  between '"+e+"'  and  '"+f+"'");
                    sql2.Append(" and x.WIPROD  between '"+e+"'  and  '"+f+"'");
                }
                
                sql1.Append("order by WIPROD desc ");
    sql2.Append(sqla+")y on x.WIPROD=y.WIPROD and x.WITOOL=y.WITOOL and x.WISEQ=y.WISEQ  where 1=1 ");                 
                sql2.Append("and y.WIPROD is null order by x.WIPROD desc");
      

  7.   

    也就是将StringBuilder  sql2 这句拆分成上下两句
      

  8.   

    还有:sql1.Append("order by WIPROD desc "); 注意order前保留空格sql1.Append(" order by WIPROD desc "); 
    下面那句sql2.Append("and 同样 sql2.Append(" and 
      

  9.   


    这样就行了,多谢各位
    StringBuilder   sql1   =   new StringBuilder( "select top "+PageSize*CurrentPage+" WIPROD,WISEQ,WITOOL from I_ITH where 1=1 "); 
              
    if(TextBox1.Text != "" & TextBox2.Text != "" )    { 
    sql1.Append( " and WITOOL between '"+a+"' and '"+b+"'  ");


    }  if(TextBox3.Text != "" & TextBox4.Text != "")    {
    sql1.Append(" and WISEQ between '"+c+"'  and  '"+d+"'");

    }
    if(TextBox5.Text != "" & TextBox6.Text != "")    {
    sql1.Append(" and WIPROD  between '"+e+"'  and  '"+f+"'");

    }

                 sql1.Append("order by WIPROD desc ");
    StringBuilder   sql2   =   new StringBuilder( "Select Top " + PageSize + "  x.* from I_ITH x left join  ("+sql1+")y on x.WITOOL=y.WITOOL and x.WISEQ=y.WISEQ and x.WIPROD=y.WIPROD  where 1=1 ");  if(TextBox1.Text != "" & TextBox2.Text != "" )    { 

    sql2.Append( " and x.WITOOL between '"+a+"' and  '"+b+"'  ");

    }  if(TextBox3.Text != "" & TextBox4.Text != "")    {

    sql2.Append(" and x.WISEQ between '"+c+"'  and  '"+d+"'");
    }
    if(TextBox5.Text != "" & TextBox6.Text != "")    {

    sql2.Append(" and x.WIPROD  between '"+e+"'  and  '"+f+"'");
    }
    sql2.Append("and y.WIPROD is null order by x.WIPROD desc");
      

  10.   

    贴上来看看啊,不用那么多if也好,就是把sql2分开比较麻烦。
      

  11.   

    (") (sqla+") 可以这样接起来吗?
      

  12.   

    StringBuilder   sql1   =   new StringBuilder( "select top "+PageSize*CurrentPage+" WIPROD,WISEQ,WITOOL from I_ITH where 1=1 "); 
    string sqla=sql1.ToString();StringBuilder   sql2   =   new StringBuilder( ")y on x.WIPROD=y.WIPROD and x.WITOOL=y.WITOOL and x.WISEQ=y.WISEQ  where 1=1 ");      
                if(TextBox1.Text != "" & TextBox2.Text != "" )               { 
                    sql1.Append( " and WITOOL between '"+a+"' and '"+b+"'  ");
                    sql2.Append( " and x.WITOOL between '"+a+"' and  '"+b+"'  ");
            
                }             if(TextBox3.Text != "" & TextBox4.Text != "")               {
                    sql1.Append(" and WISEQ between '"+c+"'  and  '"+d+"'");
                    sql2.Append(" and x.WISEQ between '"+c+"'  and  '"+d+"'");
                }
                if(TextBox5.Text != "" & TextBox6.Text != "")               {
                    sql1.Append(" and WIPROD  between '"+e+"'  and  '"+f+"'");
                    sql2.Append(" and x.WIPROD  between '"+e+"'  and  '"+f+"'");
                }
                
                sql1.Append("order by WIPROD desc ");
                sql2="Select Top " + PageSize + "  x.* from I_ITH x left join  ("+ sqla + sql2 --不知道这样语法对不对,作用拼接java 的语法忘了,应该有拼接串的,如果不行.insert(int, String)应该有的,关健要先算一下  "Select Top " + PageSize + "  x.* from I_ITH x left join  ("的长度,或新加一字符串变量(如StringBuilder   sql3   =   new StringBuilder( "Select Top " + PageSize + "  x.* from I_ITH x left join  ("+ sqla + sql2 );然后下面那句改成sql3.Append...    
                sql2.Append("and y.WIPROD is null order by x.WIPROD desc");
      

  13.   

    学习!为计算机软硬件工程师及相关技术人员提供兼职赚钱的好机会,服众网帮您实现,http://www.forstrong.net