Link to home
Start Free TrialLog in
Avatar of TBSupport
TBSupport

asked on

T-SQL Updating a Field in the Last and Next to Last Rows

Hello:

I need to update the "percentage" field of the last and next to last rows of table GL00103.  The last row needs to be 20, and the next to last row needs to be 15.

Please help!  Below are two queries.  I need to know what to put in the clause of the first query that says "where the row is the last row" and in the second query that says "where the row is the next to the last row":

UPDATE GL00103 SET (SELECT (GL00103.PRCNTAGE) FROM GL00103 'where the row is the last row') = 20
from GL00103
INNER JOIN GL00100 ON GL00103.ACTINDX = GL00100.ACTINDX
where GL00100.ACCTTYPE = '3' and GL00100.FXDORVAR = '1' AND GL00100.ACTNUMBR_2 = '6190'

UPDATE GL00103 SET (SELECT (GL00103.PRCNTAGE) FROM GL00103 'where the row is the next to the last row') = 15
from GL00103
INNER JOIN GL00100 ON GL00103.ACTINDX = GL00100.ACTINDX
where GL00100.ACCTTYPE = '3' and GL00100.FXDORVAR = '1' AND GL00100.ACTNUMBR_2 = '6190'

Thanks!  Much appreciated!

TBSupport
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TBSupport
TBSupport

ASKER

Thanks, angelIII!!!!!

That worked.  The only thing that I did slightly different was that I put in (for the "ORDER BY") Order by GL00103.DEX_ROW_ID DESC.

Thanks, again!

TBSupport