62,046
社区成员
发帖
与我相关
我的任务
分享
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from table where 1=1");
if(!string.IsNullOrEmpty(start_date) && !string.IsNullOrEmpty(end_date))
{
strSql.AppendFormat(" and y between '{0} 00:00:00' and '{1} 23:59:59.999'",start_date,end_date);
}
else if(!string.IsNullOrEmpty(start_date))
{
strSql.AppendFormat(" and y >='{0} 00:00:00'",start_date);
}
else{
strSql.AppendFormat(" and y <= '{1} 23:59:59.999'",end_date);
}
start_date:你输入的开始日期 、end_date: 你输入的结束日期select * from table where convert(varchar(8),Y,112) between '20141110' and '20141120'
select * from table where convert(varchar(8),Y,112) >= '20141110'
select * from table where convert(varchar(8),Y,112) <= '20141120'
string sql="selecr *from where date";
if (!txtDateB.Text.Trim().Length > 0)
{
sql += string.Format("date >= '{0}'" , txtDateB.Text.Trim());//选取录入日期大于查询日期的数据
}
if (!txtDateE.Text.Trim().Length > 0)
{
sql += string.Format("and date <= '{0}'", DateTime.Parse(txtDateE.Text.Trim()).ToString("yyyy-MM-dd") + " 23:59:59");//选取录入日期小于查询日期的数据
}