我有两张桌子,Table A
有Order No
,Order Line
,receiving no
,receiving date
,receiving qty
。
Order Order Line Receiving No Receiving Date Receiving Qty
A 1 455555 12/01/2013 10
A 1 455556 12/01/2013 15
A 1 455557 15/01/2013 7
A 1 455558 16/01/2013 10
A 1 455559 16/01/2013 10
A 1 455560 16/01/2013 15
A 1 455561 31/01/2013 7
Table B
有Order No
,Order Line
,Invoice no
,Invoice Qty
,Invoice Date
。
Order Order Line Invoice no Invoice Date Invoice Qty
A 1 333331 13/01/2013 32
A 1 333332 15/01/2013 10
A 1 333333 01/02/2013 32
如何创建存储过程以将Invoice No
,Invoice Qty
和Invoice Date
从Table B
更新为Table A
?
我对存储过程非常陌生,任何帮助都将不胜感激。
期望的输出:
Order Order Line Receiving No Receiving Date Receiving Qty Invoice No Invoice Date Invoice Qty
A 1 455555 12/01/2013 10 333331 13/01/2013 10
A 1 455556 12/01/2013 15 333331 13/01/2013 15
A 1 455557 15/01/2013 7 333331 13/01/2013 7
A 1 455558 16/01/2013 10 333332 15/01/2013 10
A 1 455559 16/01/2013 10 333333 01/02/2013 10
A 1 455560 16/01/2013 15 333333 01/02/2013 15
A 1 455561 31/01/2013 7 333333 01/02/2013 7
答案 0 :(得分:0)
将此查询写入存储过程
UPDATE TableA
SET ta.RecievingNo = tb.InvoiceNo,
ta.RecievingDate = tb.InvoiceDate
ta.RecievingQty = tb.InvoiceQty
FROM TableA ta
INNER JOIN TableB tb
ON ta.Order = tb.Order AND ta.OrderLine=tb.OrderLine