SQL Server - update query sum of month then update other column last date

Asked By farrukh on 10-Apr-12 01:45 PM
Dear All,

I need to write a query that sum the data of every month data suppose column name test and update the sum value to last date of the month in column test1?

Thanks
hammeed
Pat Hartman replied to farrukh on 10-Apr-12 10:20 PM
Storing calculated values violates generally accepted practices plus you haven't provided enough information.  If you are going to sum the records for a particular month, where are you going to store the sum?  You said you want to update a column named "test" but where would that column be?  And if you were thinking of storing it in the table where the detail data lives, what record did you want to update?
The best, most correct solution is to calculate the sums as you need them in queries and reports.  That way you know they are always accurate and current.
Somesh Yadav replied to farrukh on 11-Apr-12 12:41 AM
check here so many examples are explained over here,

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3170642805938
farrukh replied to Pat Hartman on 11-Apr-12 09:17 AM
Sorry to not tell in detail actually i have daily data in on column1 of the same table for each month , i need to make it a monthly value and then store it in the last date of each month in column 2? it look ocward reporting is the best idea but i have to store sum of daily values to the end of month in sum shape ?

sorry if i cannot understand well any idea ?


Thanks
Farrukh
Pat Hartman replied to farrukh on 11-Apr-12 09:10 PM
No.  You don't need to store the sum.  You especially don't need to store the sum in a detail record.  You need to sum the data in your reports or queries as you need it.  If you can post the table definition and a small sample of data, someone will help you create a query that sums the detail.