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 条件一:执行的结果 和 条件二:执行的结果 是不一样的,
我想知道怎么将 条件一和条件二的语句进行拼接,合并成一条语句 执行,
返回我想要得到的结果集.... 有没有哪个会做的啊?
调试欢乐多
if(条件)
{
sql+=and a.fxyz like '%_1__3_______%' ;
}
else
{
sql+=and a.fxyz like '%_1__3__2__4_%' ;
}
意思你应该能看懂
or a.fxyz like '%_1__3__2__4_%')
where a.ftype like '%___%' and (a.fxyz like '%_1__3_______%' or a.fxyz like '%_1__3__2__4_%')
where a.ftype like '%___%' and (a.fxyz like '%_1__3_______%'
or a.fxyz like '%_1__3__2__4_%')
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_%'
}
or a.fxyz like '%_1__3__2__4_%')
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_%' 合并起来
{ 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);
}
where (a.ftype like '%___%' and a.fxyz like '%_1__3_______%') or (a.ftype like '%___%' and a.fxyz like '%_1__3__2__4_%')就可以了