Thursday, December 29, 2011

Can C# Interfaces have fields

Most of the people answer No to this question. This happens so because which ever thing present in interface has to be Implemented in the class which implemets The Interface.
Here is an Example of this

interface Iclass
    {
        int i { get; set; }
    }

class Class : Iclass
    {

        #region Iclass Members

        public int i
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }



Monday, October 3, 2011

Update statement using Case

Update statement using case in SQL.
 where the city is 'Agra Cantt' Update it to Agra
and where it is New Delhi update It to Delhi



Update dbo.TableEmployee
Set TableEmployee.City= Case 
  When TableEmployee.City='New Delhi' then 'Delhi'
  When TableEmployee.City='Agra Cantt' then 'Agra'
End

Friday, September 30, 2011

Find the Nth Highest Salary record in Sql Server 2005

This is one of the very basic SQL query asked by most of the Interviewers.
This goes like....

Select Top 1 * from
(
Select Top N *  from dbo.Table Order By Table .Salary Desc
)  a
Order By Table .Salary Asc
This query is only valid if there are no multiple entries.

for multiple entries the dence_rank() function may hold good

Select dence_rank() over(order by salary desc) as rank   from dbo.Table  where rank=n