Thursday, May 26, 2011

Track Error in Javascript Page

Many times we have faced problems to find what is javascript errors and exactly where??
To track javascript error, It is a good practice to write code in Try..Catch
but sometimes some small syntax error are not allowing to execute the whole js file.
so to track such error during development, we can track by this sample code
  <script type="text/javascript">
        onerror = CallOnError;
        function CallOnError(msg, url, line) {
            var strErrMessage = "";
            strErrMessage += "Message: " + msg + "\n";
            strErrMessage += "Page: " + url + "\n";
            strErrMessage += "Line Number: " + line + "\n\n";
            return true;

Here is a sample error

try to put on your page

  <script type="text/javascript">
            alert('This is First Test Page);

Enjoy Coding

Monday, May 16, 2011

Second Highest Salary- Sql Query

Create Table #Emp(id int identity primary key,
    Emp varchar(100),
    Salary int)

insert into #Emp
select 'XXXX',17000 union all
select 'DDDD',21000 union all
select 'WWWW',30000 union All
Select 'HHHH',21000 union All
select 'CCCC',30000 union All
Select 'TTTT',21000 union All
SElect 'PPPP',21000

select * from #Emp

select #Emp.* 
from (select ROW_NUMBER() over (order by salary desc) as RowNumber, Salary
   from #Emp
    group by Salary) as tempEmp inner join #Emp on tempEmp.Salary = #Emp.Salary
   where tempEmp.RowNumber=2

Drop Table #Emp

Data Will Look like this


Output will be like this