If it's sql server 2005 then you can do thisDECLARE @accounts TABLE ( [accountNo] INT , [timeStamp] DATETIME , [deposit] MONEY , [withdrawl] MONEY )INSERT @accounts ([accountNo], [timeStamp], [deposit], [withdrawl]) SELECT 1, '20091203', 50, 0UNION SELECT 1, '20091202', 0, 150UNION SELECT 1, '20091201', 10000, 0UNION SELECT 2, '20060101', 500, 0UNION SELECT 3, '20091109', 0, 40UNION SELECT 3, '20090101', 100, 0UNION SELECT 3, '20091201', 0, 1000UNION SELECT 3, '20050505', 0, 10SELECT a.[account No] , a.[time stamp] , a.[Deposit] , a.[Withdrawl]FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY [accountNo] ORDER BY [timeStamp] DESC) AS [pos] , [accountNo] AS [Account No] , [timeStamp] AS [Time Stamp] , [deposit] AS [Deposit] , [withdrawl] AS [Withdrawl] FROM @accounts ) aWHERE a.[pos] < 3
Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION