none
Sql server query in C# RRS feed

  • Question

  • Hi! I am new to programming in C# and using databases.

    I have written a code to download data from a website on a daily basis and store it in a sql server database.

    So my table looks like 

    Id   date   Value Cumulative

    1    Jan1     1

    2    jan1      0.75

    3    Jan 1      0.5

    1     Jan 2    0.4

    7     Jan 2     0.6

    2     Jan 3     0.9

    8      Jan 3     0.3

     

    I wan to write an sql query which will calculate the cumulative of the value on the same Id for the different days.

    For example.,

    Id   date   Value Cumulative

    1    Jan1     1          1

    2    jan1      0.75     0.75

    3    Jan 1      0.5        0.5

    1     Jan 2    0.4         1.4

    7     Jan 2     0.6          0.6

    2     Jan 3     0.9         1.65

    8      Jan 3     0.3          0.3

    Thanx in advance.

     

    • Moved by Bob Beauchemin Monday, November 15, 2010 3:24 PM Moved to a more relevent forum. Also, posting T-SQL questions is best in the Transact-SQL forum. (From:.NET Framework inside SQL Server)
    Monday, November 15, 2010 2:29 PM

Answers

  • Your query would look something like

    SELECT Id, SUM(Cumulative) FROM MyTableNameHere GROUP BY Id


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by liurong luo Monday, November 22, 2010 12:12 PM
    Tuesday, November 16, 2010 11:33 AM
    Moderator

All replies

  • Your query would look something like

    SELECT Id, SUM(Cumulative) FROM MyTableNameHere GROUP BY Id


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by liurong luo Monday, November 22, 2010 12:12 PM
    Tuesday, November 16, 2010 11:33 AM
    Moderator
  • Hello,

    Is there any update, please? Please let us know if you need more help.

    Thanks a lot!


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Thursday, November 18, 2010 9:51 AM