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
Microsoft SQL Server 2008Microsoft SQL Server 2005SSRS

Avatar of undefined
Last Comment
TBSupport

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
TBSupport

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck