asp.net sql语句拼接问题 20
有两个文本框,一个为开始日期,一个为结束日期进行查询,我只能做成这样stringtime1="",time2="",cond="";time1=ksrq.Text;tim...
有两个文本框,一个为开始日期,一个为结束日期进行查询,我只能做成这样
string time1="",time2="",cond="";
time1 = ksrq.Text;
time2=jsrq.Text;
cond = "where 进仓时间>='" + time1 + "' and 进仓时间<='" + time2 + "'";
string sql = "select distinct(进仓编号),仓库,进仓时间 from ck_进仓主表 zb inner join ck_进仓明细 mx on zb.进仓主键=mx.进仓主键 " + cond + " and 仓库='浦东'order by 进仓编号";
但不能做到随便哪个文本框有日期都能查,类似于这样
if (time1.Trim() != "")
{
cond = cond + "and 日期>='" + time1 + "'";
}
if (time2.Trim() != "")
{
cond = cond + "and 日期<='" + time2 + "'";
if (cond != "")
{
sql1 = "select distinct(进仓编号),仓库,进仓时间 from ck_进仓主表 zb inner join ck_进仓明细 mx on zb.进仓主键=mx.进仓主键 " + cond + " and 仓库='浦东'order by 进仓编号";
}
但我改来改去,还是不行
提示sql 语句出错 展开
string time1="",time2="",cond="";
time1 = ksrq.Text;
time2=jsrq.Text;
cond = "where 进仓时间>='" + time1 + "' and 进仓时间<='" + time2 + "'";
string sql = "select distinct(进仓编号),仓库,进仓时间 from ck_进仓主表 zb inner join ck_进仓明细 mx on zb.进仓主键=mx.进仓主键 " + cond + " and 仓库='浦东'order by 进仓编号";
但不能做到随便哪个文本框有日期都能查,类似于这样
if (time1.Trim() != "")
{
cond = cond + "and 日期>='" + time1 + "'";
}
if (time2.Trim() != "")
{
cond = cond + "and 日期<='" + time2 + "'";
if (cond != "")
{
sql1 = "select distinct(进仓编号),仓库,进仓时间 from ck_进仓主表 zb inner join ck_进仓明细 mx on zb.进仓主键=mx.进仓主键 " + cond + " and 仓库='浦东'order by 进仓编号";
}
但我改来改去,还是不行
提示sql 语句出错 展开
1个回答
展开全部
sql1 = "select distinct(进仓编号),仓库,进仓时间 from ck_进仓主表 zb inner join ck_进仓明细 mx on zb.进仓主键=mx.进仓主键 and 仓库='浦东'";
if (time1.Trim() != "")
{
sql1 += " and 日期>='" + time1 + "'";
}
if (time2.Trim() != "")
{
sql1 += " and 日期>='" + time2 + "'";
}
sql1+=" order by 进仓编号";
----------------------
看不太懂你讲的是什么意思,看下是不是这样
if (time1.Trim() != "")
{
sql1 += " and 日期>='" + time1 + "'";
}
if (time2.Trim() != "")
{
sql1 += " and 日期>='" + time2 + "'";
}
sql1+=" order by 进仓编号";
----------------------
看不太懂你讲的是什么意思,看下是不是这样
追问
不对,谢谢你,方便留个qq 吗,方便请教
追答
1619741667
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询