TSQL-Accmulations



I need an appropriate select statement for my case, the case is a table with
two columns (row id ,col1) I want to retrieve a three columns
RowId, col1 ,accumulation of col1

I wrote this select statement, but the performance is going down is there an
alternative way for writing this SQL statement

SELECT RowID ,Col1, (SELECT SUM(Col1) from tablehh where RowID <=aa.RowId)
AS Col2 FROM tablehh as aa ORDER BY Col1,Col2
The output should be like this:

RowId Col1 Col2
1 10 10
2 100 110
3 15 125
4 20 145]

Col2 is the accumulation of col1

thx;
batool.



.



Relevant Pages

  • Re: Inserting multiple records into two tables...with a twist
    ... I assume that you have an IDENTITY column, ... reason would typically be a high rate of concurrent insertions.) ... INSERT tblB(id, col1, col2, ... ...
    (comp.databases.ms-sqlserver)
  • Dynamic PreparedStatements with Variable In Parameters
    ... AND col2=? ... AND col3=? ... I have to start coding tomorrow so I'm eager ...
    (comp.lang.java.programmer)
  • Re: TSQL-Accmulations
    ... Write an MS query that downloads the non-computed data into an Excel sheet and then have a column in Excel do the accumulations for you. ... RowId, col1,accumulation of col1 ... AS Col2 FROM tablehh as aa ORDER BY Col1,Col2 ...
    (microsoft.public.sqlserver.clients)
  • Re: Required property of Primary Key fields
    ... col1 INTEGER NOT NULL, ... PRIMARY KEY (col1, col2) ... it's a bit pointless because the INSERT will fail with a "primary key ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Strange effects of Cast
    ... Cast to tuncate strings. ... In the query below although I get the expected result in COL1 and COL2 ... COL3 and COL4 return only three characters. ...
    (comp.databases.oracle.misc)

Loading