Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jcarrallo
Starting Member
35 Posts |
Posted - 2014-06-12 : 17:26:06
|
Hi SQL Team,I wonder if you can help me with this:I want to update records in 1 table with the result of a select statement.The table is called 'MPR_Portfolio_Transactions' and contains the following fields:[PTR_SEQUENCE],[PTR_DATE],[PTR_SYMBOL],[PTR_QUANTITY],[PTR_ACUM]And the select statement is like this:SELECT SUM(PTR_QUANTITY) OVER (PARTITION BY PTR_SYMBOL ORDER BY PTR_DATE, PTR_SEQUENCE) AS 'ACUMULADO'FROM MPR_portfolio_transactionsORDER BY PTR_SYMBOL, PTR_DATE, PTR_SEQUENCEThis select statement generates one line per existing record. And what I would like to do next is to UPDATE the field 'PTR_ACUM' with the result of the 'ACUMULADO'the key is PTR_SEQUENCEPlease help!!!thanks in advanced.Jay |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-06-12 : 17:29:28
|
Maybe this:UPDATE mSET PTR_ACUM = ACUMULADOFROM MPR_portfolio_transactions mJOIN ( SELECT PTR_SEQUENCE, SUM(PTR_QUANTITY) OVER (PARTITION BY PTR_SYMBOL ORDER BY PTR_DATE, PTR_SEQUENCE) AS 'ACUMULADO' FROM MPR_portfolio_transactions) dtON m.PTR_SEQUENCE = dt.PTR_SEQUENCE Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
 |
|
jcarrallo
Starting Member
35 Posts |
Posted - 2014-06-12 : 17:44:25
|
Brilliant!many thanks Tara |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|