62,067
社区成员
发帖
与我相关
我的任务
分享
create procedure proc_find
@user_login_name varchar(50)=null,
@user_nick_name varchar(50)=null
@birthday varchar(50)=null
AS
select * from T_USER
where (@user_login_name is null or user_login_name=@user_login_name)
and (@user_nick_name is null or user_nick_name=@user_nick_name)
and (@birthday is null or birthday=@birthday)
string sqlstr="";
if(USER_LOGIN_NAME!=""&&USER_LOGIN_NAME!=null)
sqlstr+=" and USER_LOGIN_NAME='"+USER_LOGIN_NAME+"'";
if(USER_NICK_NAME!=""&&USER_NICK_NAME!=null)
sqlstr+=" and USER_NICK_NAME='"+USER_NICK_NAME+"'";
if(BIRTHDAY!=""&&BIRTHDAY!=null)
sqlstr+=" and BIRTHDAY='"+BIRTHDAY+"'";
sqlstr="select * from t_user where 1=1"+sqlstr;
private string SearchSql(string loginName,string nickName,string birthday)
{
string sql = "select * from t_user";
bool hasSearch = false;
if(loginName.Length > 0)
{
hasSearch = true;
sql += " where USER_LOGIN_NAME = '"+loginName+"'";
}
if(nickName.Length > 0)
{
if(hasSearch)
{
sql += " and USER_NICK_NAME = '"+nickName+"'";
}
else
{
sql += " where USER_NICK_NAME = '"+nickName+"'";
hasSearch = true;
}
}
if(birthday.Length > 0)
{
if(hasSearch)
{
sql += " and BIRTHDAY='"+birthday+"'";
}
else
{
sql += " where BIRTHDAY='"+birthday+"'";
}
}
}