试改下: 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");
也就是将StringBuilder sql2 这句拆分成上下两句
还有:sql1.Append("order by WIPROD desc "); 注意order前保留空格sql1.Append(" order by WIPROD desc "); 下面那句sql2.Append("and 同样 sql2.Append(" and
这样就行了,多谢各位 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");
贴上来看看啊,不用那么多if也好,就是把sql2分开比较麻烦。
(") (sqla+") 可以这样接起来吗?
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");
放在sql1下面才行。但是下面的if条件成立的时候,先加order by 再加and 语句 就有问题了。难道要上下都放一个order by?
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");
下面那句sql2.Append("and 同样 sql2.Append(" and
这样就行了,多谢各位
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");
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");