Join Dotnetcodes is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login MVC Interview Questions Answers Interview Questions
Serial Number in SSRS Articles
Get Started Developing for Android Apps with Eclipse Articles
How to Print a Crystal Report direct to printer Articles
Razor View Engine Interview Questions Answers Interview Questions
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
SPIRE PDF Library Articles
Infosys Interview Questions Interview Questions
Html5 interview questions and answers Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
SharePoint 2010 interview Questions Answers Interview Questions
Submit Articles | More Articles..

How to get the second last record from a Table.

Posted By: syedshakeer On:7/23/2010 4:53:01 AM in:Source Codes Category:Sql Server Hits:3071
Get the second last record from a Table 

insert into dupemp(name,salary,deptno) values('1sd',4000,12)

insert into dupemp(name,salary,deptno) values('2sd',4000,12)

insert into dupemp(name,salary,deptno) values('3sd',4000,12)

insert into dupemp(name,salary,deptno) values('6sd',4000,12)

insert into dupemp(name,salary,deptno) values('4sd',4000,12)


with CTE as(select *,ROW_NUMBER() over(order by (select 0))as row from dupemp )
select * from cte where row=(select min(row) from cte where row in(select top 2 row from cte order by row desc))


Name salary deptno

6sd  4000    12
comments powered by Disqus
User Profile
Working as Windows Mobile Developer
Hyderabad , India
Email :You must Log In to access the contact details.
Latest Post from :syedshakeer
List the highest salary from each department?
View: 3259 | Submitted on: 7/23/2010 5:00:19 AM
How to get the second last record from a Table.
View: 3071 | Submitted on: 7/23/2010 4:53:01 AM
How to get DATE without DATE TIME using SQL SERVER?
View: 1785 | Submitted on: 7/23/2010 4:50:59 AM
Add Select in DropDownlist
View: 1879 | Submitted on: 7/23/2010 4:47:45 AM
Submit Articles | All Post of This User..

All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher