最多只有33分,全给你罢,问题要给我解决!都三天了!不然我一直提,提。。。。

C员外 2001-09-26 08:24:08

公司让我半路接一个MIS项目,数据结构没法变(已在用):
库存表(名称、规格、当前库存件数,当前库存重量);
出库表(名称、规格、出库件数,出库重量,出库日期);
入库表(名称、规格、入库件数,入库重量,入库日期);

现在客户要求查询:某一期间(比方2000-09-10到2001-09-10,(当前为2001-09-20))内库存数、出库数、入库数;可以选择名称、规格缩小范围,或不选查询全部。

在delphi5中,我用 TAdodataset(TADOQUERY)如何写SQL语句?
...全文
154 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sonhong 2001-09-26
  • 打赏
  • 举报
回复
select temp1.mc,temp1.csum,temp2.rsum

from (mc,sum(chukjs) csum from chuk where rq >= :rq1 and rq <= :rq2 group by mc) temp1,
(mc,sum(rukjs) rsum from ruk where rq >= :rq1 and rq <= :rp2 group by mc) temp2

where temp1.mc = :mc
and temp2.mc = temp1.mc

日期格式没有定义,
库存数没有求
名称、规格缩小范围,或不选查询全部 好像要写三个Sql
hswwwdelphi 2001-09-26
  • 打赏
  • 举报
回复
nb
yxjjx 2001-09-26
  • 打赏
  • 举报
回复
帮你up
clacklin 2001-09-26
  • 打赏
  • 举报
回复
我前面的SQL语句是用来生成一个视图,然后你想怎么查询就怎么查吧。
cszhz 2001-09-26
  • 打赏
  • 举报
回复
或者动态添加条件
if con1 then
strSQL := strSQL + str_con1;
if con2 then
strSQL := strSQL + str_con2;
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
最后加上 and 1=1
cszhz 2001-09-26
  • 打赏
  • 举报
回复
if name = '' then
name := '%';
if date1 = '' then
date1 :='1900-01-01';
if date2 = '' then
date2 :='2099-12-31';

strSQL := 'select inv.name,inv.qty,in.count,out.count from in,out,inv where inv.name like '''+name +''' and' (out.date between '+datetostr(date1) + ' and'
+ datetostr(date2) +') +'and (in.date between '+datetostr(date1) + ' and'
+ datetostr(date2) +') where in.name = out.name and in.name = inv.name and out.name = inv.name';
di2000 2001-09-26
  • 打赏
  • 举报
回复
我认为也可以使用表的连接,在用模糊查询
songlichao 2001-09-26
  • 打赏
  • 举报
回复
clacklin(海风)的语句是对的。
查出的库存数是当前20010920的库存数。
songlichao 2001-09-26
  • 打赏
  • 举报
回复
至于查询条件,那是简单小事。
我可以帮你的。
songlch@263.net
clacklin 2001-09-26
  • 打赏
  • 举报
回复
不知你具体的查询要求是什么,但通过union是可以做到了。我把我原先写的查询库存清单语句让你参考一下吧。
select c.goodscode,e.goodsname,c.amount
from workthingscode e,
(select goodscode,sum(amount) amount
from
(select a.goodscode,a.amount,a.indate dd
from workthingsin a
union
select b.goodscode,-b.amount,b.outdate dd
from workthingsout b
order by goodscode,dd)
group by goodscode) c
where c.goodscode=e.goodscode
songlichao 2001-09-26
  • 打赏
  • 举报
回复
这个SQL并不算太复杂。
问题是库存数只能是一个点。
你是要当前的库存数(20010920),还是20000910,还是20010910。
知道了这个,就可以写了。
要用到SELECT的嵌套。
11830 2001-09-26
  • 打赏
  • 举报
回复
像上面这相就算名称或规格为空的话就认为是全部,至于时间你可以要最后加上 and tabledate between 开始时间 and 结束时间
11830 2001-09-26
  • 打赏
  • 举报
回复
用like语句
名称:=名称;
规格:=规格;
开始时间:=开始时间;
..
..
adoquery.sql.add('select * from table where 名称 like '+''''+'%'+名称+'%'+''''+' and 规格 like '+''''+'%'+规格+'%'+''''....
就可以了

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧