जगदीश खोलिया

Monday, August 8, 2016

Find Nth Highest Salary in a table and Highest Salary for each department in a table

Find Nth Highest Salary in a table:

CREATE TABLE EMP
(
NAME VARCHAR(20),
SALARY INT,
DEPTNO INT
)

2nd Highest Salary in a table:

;WITH TMPTBL AS(SELECT TOP 2 NAME,SALARY FROM EMP ORDER BY SALARY DESC)
SELECT TOP 1* FROM TMPTBL ORDER BY SALARY
 


Or Using Row_Number()

;WITH CTE AS(SELECT ROW_NUMBER() OVER(ORDER BY SALARY DESC) ROW,SALARY,DEPTNO FROM EMP)
SELECT * FROM CTE WHERE ROW = 2


Find Nth Highest Salary for each department in a table:

;WITH CTE AS(SELECT ROW_NUMBER() OVER(PARTITION BY DEPTNO ORDER BY SALARY DESC) ROW,SALARY,DEPTNO FROM EMP)
SELECT * FROM CTE WHERE ROW=2

Monday, February 17, 2014

Accessing & Assigning the Session Variable using Javascript

Assigning the ASP.NET Session Variable using Javascript:
<script type="text/javascript">
function SetUserName()
{
    var userName = "Jagdish Kholiya";
    '<%Session["UserName"] = "' + userName + '"; %>';
     alert('<%=Session["UserName"] %>');
}
</script>
Accessing ASP.NET Session variable using Javascript:
<script type="text/javascript">
    function GetUserName()
    { 
        var username = '<%= Session["UserName"] %>';
        alert(username );
    }
</script>