Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Answer based on the OP's updated question: <a href="http://sqlfiddle.com/#!3/dba13/22" rel="nofollow">http://sqlfiddle.com/#!3/dba13/22</a></p> <pre><code>with SeqInvoice as ( select *, row_number() over(order by InvoiceId) rn from invoice ) ,SeqDate as ( select *, row_number() over(order by IssuedDate) rn from invoice ) update SeqInvoice set IssuedDate = sd.IssuedDate from SeqDate sd where sd.rn = SeqInvoice.rn; select * from Invoice; </code></pre> <p>Output:</p> <pre><code>| INVOICEID | STORECUSTOMERID | ISSUEDDATE | AMOUNT | ISPENALTY | EMPLOYEEID | ---------------------------------------------------------------------------------------------------- | 1 | 13 | September, 19 2006 02:00:00-0700 | 244 | 0 | 41 | | 2 | 31 | October, 24 2006 02:00:00-0700 | 81 | 0 | 34 | | 3 | 23 | December, 11 2006 01:00:00-0800 | 184 | 0 | 46 | | 4 | 28 | January, 09 2007 01:00:00-0800 | 231 | 0 | 17 | | 5 | 36 | January, 12 2007 01:00:00-0800 | 121 | 0 | 22 | | 6 | 28 | January, 15 2007 01:00:00-0800 | 240 | 0 | 17 | | 7 | 15 | April, 05 2007 02:00:00-0700 | 193 | 0 | 47 | | 8 | 21 | November, 21 2007 01:00:00-0800 | 172 | 0 | 4 | </code></pre> <p><strong>UPDATE</strong></p> <p>Here's a way without directly updating the CTE, updates the base table directly: <a href="http://sqlfiddle.com/#!3/dba13/24" rel="nofollow">http://sqlfiddle.com/#!3/dba13/24</a></p> <pre><code>with SeqInvoice as ( select *, row_number() over(order by InvoiceId) rn from invoice ) ,SeqDate as ( select *, row_number() over(order by IssuedDate) rn from invoice ) update I set IssuedDate = sd.IssuedDate from Invoice i join SeqInvoice si on si.InvoiceId = i.InvoiceId join SeqDate sd on sd.rn = si.rn; select * from Invoice; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload