日期:2014-05-17  浏览次数:20711 次

求一段组合查询的代码 在线等~~~~
有时间段的组合查询:
接收到四个值:account;   prod;   bdate;   edate;
数据库里有字段   account,prod,date
bdate与edate是两个日期,从   date里查找在这个日期区间里符合条件的记录
如果account;prod;bdate;edate四项都有值的话,就是从数据库里查找出在bdate-edate时间段account=account,prod=prod的所有记录,
如果某项值为空,如account为空,那么就是查找在bdate-edate时间段里prod=prod的所有记录。
bdate与edate只会都有值或都为空。

昨晚写了半天   还是不好使,现在来求段代码,学习学习。     谢谢!

------解决方案--------------------
querysql= "select * from t_table where 1=1 "
if account = " " Then querysql=querysql& " and account= ' "&account& " ' "
同样写下去就可以了 不过日期最好先处理以下 比较特殊
最好先不写日期的调试好别的再加上日期 便于处理问题

------解决方案--------------------
account; prod; bdate; edate
if account= " " then
account1= " "
else
account1= " and account= ' "&account& " ' "
end if
if prod= " " then
prod1= " "
else
prod1= " and prod= ' "&prod& " ' "
end if
sql= "select * from table where 1=1 "&account1& " "&prod1& " and date> = 'bdate ' and date <= 'edate ' "

------解决方案--------------------
好象最后一句日期查询错误

如果你用的是ACCESS
应该

sql= "select * from work where 1=1 "&account1& " "&prod1& " and date> =# "&bdate& "# and date <=# "&edate& "# "