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
根據處方明細查詢出從哪些庫存批次進行扣減,得出的結果中有多個序號是因為一個批次數量不足,從多個批次扣減的,處方中允許出現相同規格的藥品,麻煩大佬些指點下,能不能不用游標,直接查詢出結果
uj5u.com熱心網友回復:
別沉啊,大神些轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/56803.html
標籤:疑難問題
上一篇:有沒有人會做虎牙直播的降低延遲
下一篇:求大佬看看putty出現neetwork error;connection timed out這種情況怎么辦?ip地址沒輸錯,選的ssh,VMware也關了
