string strSQL = "select * from member where sexs=?sexs or age>=?minage and age<=?maxage or continent=?continent or country=?country or location=?location";
我想要的结果是:
当我选择了性别,其他没有选择,就按性别查询,如果,添加了一个条件,比如说年龄,那么,就有两个条件根据性别和年龄,同时满足两个条件查询。以此类推...如果,全选择就按全部条件.. 请问这个sql语句要怎么写?表述不详细的地方,请说 我现在写的sql,没有达到我想要的结果。。能够分开查询,但是,同时选择两个条件以上,那么,两个条件的东西都会查询出来...
if(strAge!="")
{
strsql+=" and age="+strage;
}
...省略
where (sexs=?sexs or ?sexs = 默认)
and (age = ?age or ?age = 默认)查询条件输入时 根据查询条件,未输入时,给定默认值
例 age 默认为0
and(age=25 or 25 = 0)
and(age = 0 or 0 = 0)
能帮我上面那个sql改一下吗?,就改两个条件,我看的不是太懂
" BestSendTime,Payment,Invoice,Message,DeliveryMode,CreateDate,isStatus,deliveryStatus,transactionState,CashStatus,isAudit FROM Hd_Orders as a ";
#region
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null)
|| (od.TransactionState != "" && od.TransactionState != null) || (od.OrderNum != "" && od.OrderNum != null) || (od.TelePhone != "" && od.TelePhone != null)
|| (od.SelectOneTime != "" && od.SelectOneTime != null) || (od.SelectTwoTime != "" && od.SelectTwoTime != null) || (od.IsAudit != "" && od.IsAudit != null))
{
sql += "where "; if (od.IsStatus != "" && od.IsStatus != null)
{
sql += "a.IsStatus=@IsStatus ";
} if (od.CashStatus != "" && od.CashStatus != null)
{
if (od.IsStatus != "" && od.IsStatus != null)
{
sql += " and ";
}
sql += "a.CashStatus=@CashStatus ";
} if (od.DeliveryStatus != "" && od.DeliveryStatus != null)
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null))
{
sql += " and ";
}
sql += "a.DeliveryStatus=@DeliveryStatus ";
} if (od.TransactionState != "" && od.TransactionState != null)
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null))
{
sql += " and ";
}
sql += "a.TransactionState=@TransactionState";
} if (od.OrderNum != "" && od.OrderNum != null)
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null) || (od.TransactionState != "" && od.TransactionState != null))
{
sql += " and ";
}
sql += "a.OrderNum=@OrderNum ";
} if (od.TelePhone != "" && od.TelePhone != null)
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null)
|| (od.TransactionState != "" && od.TransactionState != null) || (od.OrderNum != "" && od.OrderNum != null))
{
sql += " and ";
}
sql += "a.Mobile=@TelePhone or a.TelePhone=@TelePhone ";
} if ((od.SelectOneTime != "" && od.SelectOneTime != null) || (od.SelectTwoTime != "" && od.SelectTwoTime != null))
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null)
|| (od.TransactionState != "" && od.TransactionState != null) || (od.OrderNum != "" && od.OrderNum != null) || (od.TelePhone != "" && od.TelePhone != null))
{
sql += " and ";
}
sql += "a.CreateDate>@SelectOneTime and a.CreateDate<@SelectTwoTime ";
} if (od.IsAudit != "" && od.IsAudit != null)
{
if ((od.IsStatus != "" && od.IsStatus != null) || (od.CashStatus != "" && od.CashStatus != null) || (od.DeliveryStatus != "" && od.DeliveryStatus != null)
|| (od.TransactionState != "" && od.TransactionState != null) || (od.OrderNum != "" && od.OrderNum != null) || (od.TelePhone != "" && od.TelePhone != null)||
(od.SelectOneTime != "" && od.SelectOneTime != null) || (od.SelectTwoTime != "" && od.SelectTwoTime != null))
{
sql += " and ";
}
sql += "a.IsAudit=@IsAudit ";
} }
#endregion
if(性别文本.length>0)
{
sql +=" and 性别='"+性别文本+"'";
}
if(年龄文本.length>0)
{
sql +=" and 年龄='"+年龄文本+"'";
}
.......以此类推
比如:
if(性别文本.length>0)
{
sql +=" and 性别='"+性别文本+"'";
}
你性别选择了.但其他的呢查询出来?还有一种情况,我选择了性别,国家,地区,其他不选择,你这样写能够实现只查询这个3个条件,其他不查询码?
string strSQL = "select * from member where sexs=?sexs or age>=?minage and age<=?maxage or continent=?continent or country=?country or location=?location";
能我把这个sql语句改一下吗?我能看的懂一点、、
ClassSearchOption cso1 = new ClassSearchOption();//用它来构造查询条件DataTable data = c1.Search(cso1);