存储过程更新无公共字段表

时间:2013-05-09 02:49:51

标签: sql sql-server-2000

我有两张桌子,Table AOrder NoOrder Linereceiving noreceiving datereceiving 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 BOrder NoOrder LineInvoice noInvoice QtyInvoice 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 NoInvoice QtyInvoice DateTable 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

1 个答案:

答案 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