Insert accumulated total to my table in SQL Server 2008 -


i want calculate running total (idd not primary or foreign key)

idd    svalue      acctotal 1       5             5 2       6             11 1       2             13 3       4             17 2       1             18 

and on

i work in many trigger didn't work:

 create trigger acc on detail   update, insert         declare @accountid int      declare @getaccountid cursor       set @getaccountid = cursor         select idd         detail       declare @tot int      set @tot = (select sum(dvalues) detail)       open @getaccountid       fetch next @getaccountid @accountid       while @@fetch_status = 0      begin         print @accountid          update detail          set acctotal = @tot          fetch next @getaccountid @accountid      end       close @getaccountid 

could not like:

@tot = (select top 1 isnull(acctotal, 0) + @newvalue detail order acctotal desc) 

this work if you're ever dealing positive number though... advice unique order best way. adding seed column work order by.

regards

liam


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -