F
fstao
Unregistered / Unconfirmed
GUEST, unregistred user!
数据库为mssql7,有一进/出仓单表,其主表dbo.jin_chu_master_ku,从表
dbo.jin_chu_detail_ku,
假如数据如下:
主表 dbo.jin_chu_master_ku (字段rq为日期、dh为单号、fx为方向,
fx=1为进仓,fx=-1为出仓)
id rq dh fx
1 00-5-1 j-1 1
2 00-5-2 j-2 -1
3 00-5-3 c-1 -1
4 00-5-3 c-2 1
从表dbo.jin_chu_detail_ku(字段id与主表id关联,pm为货品,sl为数量)
id1 id pm sl
1 1 A 10
2 1 B 15
3 2 A 20
4 2 C 10
5 3 D 10
6 4 A 10
如果查询日期从00-5-1到00-5-3库存明细表为(rq为日期、db为单号、pm为货
品、srsl为收入数量和fcsl为发出数量):
dbo.kcmxb(库存明细表):
rq dh pm srsl fcsl
00-5-1 j-1 A 10
00-5-1 j-1 B 15
00-5-2 j-2 A 20
00-5-2 j-2 C 10
00-5-3 c-1 D 10
00-5-3 c-2 A 10
语句为:
insert into kcmxb(rq,dh,hp,srsl,fcsl) select
j1.rq,j1.dh,j2.pm,j2.sl,j2.sl from jin_chu_master_ku j1,
jin_chu_detail_ku j2 where j1.id=j2.id and j1.rq>='2000-05-1'
and j1.rq<='2000-05-3' and j1.fx=1 or j1.fx=-1
我这样写不对,原因在srsl和fcsl都是j2.sl来附值的,请问如何改写?
dbo.jin_chu_detail_ku,
假如数据如下:
主表 dbo.jin_chu_master_ku (字段rq为日期、dh为单号、fx为方向,
fx=1为进仓,fx=-1为出仓)
id rq dh fx
1 00-5-1 j-1 1
2 00-5-2 j-2 -1
3 00-5-3 c-1 -1
4 00-5-3 c-2 1
从表dbo.jin_chu_detail_ku(字段id与主表id关联,pm为货品,sl为数量)
id1 id pm sl
1 1 A 10
2 1 B 15
3 2 A 20
4 2 C 10
5 3 D 10
6 4 A 10
如果查询日期从00-5-1到00-5-3库存明细表为(rq为日期、db为单号、pm为货
品、srsl为收入数量和fcsl为发出数量):
dbo.kcmxb(库存明细表):
rq dh pm srsl fcsl
00-5-1 j-1 A 10
00-5-1 j-1 B 15
00-5-2 j-2 A 20
00-5-2 j-2 C 10
00-5-3 c-1 D 10
00-5-3 c-2 A 10
语句为:
insert into kcmxb(rq,dh,hp,srsl,fcsl) select
j1.rq,j1.dh,j2.pm,j2.sl,j2.sl from jin_chu_master_ku j1,
jin_chu_detail_ku j2 where j1.id=j2.id and j1.rq>='2000-05-1'
and j1.rq<='2000-05-3' and j1.fx=1 or j1.fx=-1
我这样写不对,原因在srsl和fcsl都是j2.sl来附值的,请问如何改写?