select * from  TABLE  a  
条件一: where a.ftype like '%___%'  and a.fxyz like '%_1__3_______%' 条件二:where a.ftype like '%___%'  and a.fxyz like '%_1__3__2__4_%' T-SQL 条件一:执行的结果 和 条件二:执行的结果 是不一样的,
我想知道怎么将 条件一和条件二的语句进行拼接,合并成一条语句 执行,
  返回我想要得到的结果集....   有没有哪个会做的啊?

解决方案 »

  1.   

    string sql=select * from  TABLE  a  where a.ftype like '%___%' ;
    if(条件)

       sql+=and a.fxyz like '%_1__3_______%' ;

    else
    {
       sql+=and a.fxyz like '%_1__3__2__4_%' ;
    }
    意思你应该能看懂
      

  2.   

    where a.ftype like '%___%'  and (a.fxyz like '%_1__3_______%' 
    or a.fxyz like '%_1__3__2__4_%')
      

  3.   

    select * from  TABLE  a  
     where a.ftype like '%___%'  and (a.fxyz like '%_1__3_______%' or a.fxyz like '%_1__3__2__4_%')
      

  4.   


    where a.ftype like '%___%' and (a.fxyz like '%_1__3_______%'  
    or a.fxyz like '%_1__3__2__4_%')
      

  5.   

    select * from  TABLE  a  where a.ftype like '%___%'  and (a.fxyz like '%_1__3_______%' or a.fxyz like '%_1__3__2__4_%' )这样子就可以了。
      

  6.   

    楼主要的是T-SQL语句,不是c#语句。
    select * from  TABLE  a  
    where a.ftype like '%___%'  and 
    {
        if 条件1
            a.fxyz like '%_1__3_______%'
        else if 条件2
            a.fxyz like '%_1__3__2__4_%' 
    }
      

  7.   

    where a.ftype like '%___%' and (a.fxyz like '%_1__3_______%'  
    or a.fxyz like '%_1__3__2__4_%')
      

  8.   

    select * from  TABLE  a  
     where a.ftype like '%___%'  and a.fxyz like '%_1__3_______%' 
    unionselect * from  TABLE  a  
    where a.ftype like '%___%'  and a.fxyz like '%_1__3__2__4_%' 合并起来
      

  9.   

     public DataSet HuiyuanAll(int state, int Pagesize, int PageIndex, string username, string zhutime, string shangtime)
            {            string sql1 = "";
                string sql2 = "";
                if (username != "")
                {
                    sql1 += " and ULoginName like '%" + username + "%'";
                    sql2 += " and ULoginName like '%" + username + "%'";
                }
                if (zhutime != "")
                {                sql1 += " and  Convert(varchar(100),RegTime,23) like '%" + zhutime + "%'";
                    sql2 += " and  Convert(varchar(100),RegTime,23) like '%" + zhutime + "%'";
                }
                if (shangtime != "")
                {                sql1 += " and Convert(varchar(100),LastLogTime,23) like '%" + shangtime + "%'";
                    sql2 += " and Convert(varchar(100),LastLogTime,23) like '%" + shangtime + "%'";
                }
                string sql3 = "";
                if (sql1 != "" && sql2 != "")
                {
                    sql3 = "select count(*) from users where Del=" + state + "" + sql1 + " ;select top(" + Pagesize + ") * from users where Del=" + state + " and  Uid  not in (select top (" + Pagesize * (PageIndex - 1) + ") Uid from users where Del=" + state + " order by RegTime desc) " + sql2 + " order by RegTime desc ";            }
                else
                {
                    sql3 = "select count(*) from users where Del=" + state + ";select top(" + Pagesize + ") * from users where Del=" + state + " and  Uid  not in (select top (" + Pagesize * (PageIndex - 1) + ") Uid from users where Del=" + state + " order by RegTime desc) order by RegTime desc ";
                }
                return new DBUility.DBHelp().ExecuteDataSet(sql3, CommandType.Text, null);
            }
      

  10.   

    select * from TABLE a   
     where (a.ftype like '%___%' and a.fxyz like '%_1__3_______%') or (a.ftype like '%___%' and a.fxyz like '%_1__3__2__4_%')就可以了