troubleshooting Question

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

Avatar of TBSupport
TBSupport asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008SSRS
2 Comments1 Solution4102 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros