Update only the top 1 row in sql server

I have a table as below:

enter image description here

As You see, the column officebudge updated with value for all individual offices. i want the update happen only top 1 office
like below:

enter image description here

any suggesion to update the top 1 record?
I used below code. but it updates all the office entries:

UPDATE budget
  SET   officebudge = ISNULL(ProjectedReturnCount,0)
  FROM analyticsdata
  join
  (
  select   ofc.officeid,ofc.week,
  max(ISNULL(ofc.ProjectedReturnCount,0)) ProjectedReturnCount
  from
  BudgetOffice ofc
  INNER JOIN budget anal
  on ofc.OfficeID = anal.OfficeID
  and ofc.Week      = anal.week
  and ofc.RowStatus = 'a' 
  group by ofc.OfficeID,ofc.week
  )z
  on (z.officeid = budget.OfficeID
  and z.Week    = budget .week )

thanks for the help.


Source: sql

Leave a Reply