Update Total Hold Time

  • Hi,

    I have the following table :

    Month, Year, TeamNum, Ext, AvgHoldTime,TotSCI, TeamAvgHoldTime

    2 2008 1 200 1000 20

    2 2008 1 300 2000 40

    2 2008 2 200 3000 60

    2 2008 2 300 4000 80

    I want to update the TeamAverageHold time as a sum of Teams 1 and 2 :

    Update the TeamAvgHoldTime for Team 1 and Team 2 as a Total. sum(AvgHoldTime )/sum(TotSCI) for both TeamNum 1 and 2 as a Total i.e. 10000/200 = 50

    It should show the following after an update:

    Month, Year, TeamNum, Ext, AvgHoldTime,TotSCI, TeamAvgHoldTime

    2 2008 1 200 1000 20 50

    2 2008 1 300 2000 40 50

    2 2008 2 200 3000 60 50

    2 2008 2 300 4000 80 50

    How do I write T-SQL for updating TeamAvgHoldtime within the same table?

    Thanks

  • declare @TeamAvgHoldTime int ---<<< or decimal as you need it

    select @TeamAvgHoldTime = sum(AvgHoldTime )/sum(TotSCI)

    from #tmp

    select @TeamAvgHoldTime

    update t set TeamAvgHoldTime = @TeamAvgHoldTime

    from #tmp t

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply