22,207
社区成员
发帖
与我相关
我的任务
分享
create table #处方明细表
(
处方id int,
序号 int,
药品id int,
数量 int
)
insert into #处方明细表
select 1,1,101,10 union all
select 1,2,102,20 union all
select 1,3,101,30 union all
select 1,4,103,40
create table #库存明细表
(
入库单号 int,
入库序号 int,
药品id int,
数量 int
)
insert into #库存明细表
select 1001,1,101,20 union all
select 1001,2,102,10 union all
select 1001,3,103,50 union all
select 1002,1,101,8 union all
select 1002,2,102,30 union all
select 1003,1,101,20
--得到结果 select * from #处方明细表
处方id 序号 药品id 数量 入库单号 入库序号 扣减数量
1 1 101 10 1001 1 10
1 2 102 20 1001 2 10
1 2 102 20 1002 2 10
1 3 101 30 1001 1 10
1 3 101 30 1002 1 8
1 3 101 30 1003 1 12
1 4 103 40 1001 3 40