Find 2nd highest salary using sql
Select TOP 1 Salary
from (SELECT DISTINCT TOP 2 Salary from Employee ORDER BY Salary ASC)
a ORDER BY Salary DESC
Find 2nd highest salary using LINQ
var employee = Employees
.OrderByDescending(e => e.Salary)
.Skip(1) //skip(N-1) N is 2
.First();
If multiple employees may have equal salary and you wish to return an IEnumerable of all the employees with the second-highest salary you could do
var employees = Employees
.GroupBy(e => e.Salary)
.OrderByDescending(g => g.Key)
.Skip(1)
.First();
==========================================================
Call Server Side Code using ASP.NET AJAX and jQuery AJAX
using System.Web.Services;
try
{
//Do here server event
}
catch (Exception)
{
throw;
}
}
function MyFunction(Param1, Param2) {
$.ajax({
type: "POST",
url: "MyPage.aspx/MyMethod",
data: "{ Param1: '" + Param1+ "',Param2: '" + Param2 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: "false",
success: function (msg) {
// On success
},
Error: function (x, e) {
// On Error
}
});
Select TOP 1 Salary
from (SELECT DISTINCT TOP 2 Salary from Employee ORDER BY Salary ASC)
a ORDER BY Salary DESC
Find 2nd highest salary using LINQ
var employee = Employees
.OrderByDescending(e => e.Salary)
.Skip(1) //skip(N-1) N is 2
.First();
If multiple employees may have equal salary and you wish to return an IEnumerable of all the employees with the second-highest salary you could do
var employees = Employees
.GroupBy(e => e.Salary)
.OrderByDescending(g => g.Key)
.Skip(1)
.First();
==========================================================
Call Server Side Code using ASP.NET AJAX and jQuery AJAX
using System.Web.Services;
try
{
//Do here server event
}
catch (Exception)
{
throw;
}
}
function MyFunction(Param1, Param2) {
$.ajax({
type: "POST",
url: "MyPage.aspx/MyMethod",
data: "{ Param1: '" + Param1+ "',Param2: '" + Param2 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: "false",
success: function (msg) {
// On success
},
Error: function (x, e) {
// On Error
}
});
Thanks for this blog. provided great information. All the details are explained clearly with the great explanation. Thanks for this wonderful blog. Step by step processes execution are given clearly.Know the details about different thing.
ReplyDeleteDigital Marketing Company in Chennai