开发者

Updating a column from another's repeatable values

I have the following table

Invoice

+++++++++++++++++++++++++++
+ InvoiceId + InvoiceDate +
+开发者_开发技巧++++++++++++++++++++++++++
+   int     +     int     +
+++++++++++++++++++++++++++

InvoiceLine

++++++++++++++++++++++++++++++++++++++++++++
+ InvoiceLineId +  InvoiceId + InvoiceDate +
++++++++++++++++++++++++++++++++++++++++++++
+    int        +    int     +    int      +
++++++++++++++++++++++++++++++++++++++++++++

I recently added the last (InvoiceDate) column to the table and I would like to update it's values with the corresponding values from the Invoice table. For every InvoiceId that matches in both tables, the InvoiceDate should be added to InvoiceLine.

If more input is needed don't hesitate to ask.


Update InvoiceLine
Set InvoiceDate = Invoice.InvoiceDate 
From Invoice inner join InvoiceLine on Invoice.InvoiceId = InvoiceLine.InvoiceId


maybe something like this?

    update detail
    set invoicedate = summary.invoicedate
    from invoiceline detail 
         inner join invoice summary
             on summary.invoiceid = detail.invoiceid
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜