Monday 24 November 2014

select Nth salary from employee table using sql query with top query

SELECT MAX(EmpSalary) as 'EmpSalary' from tblEmployeeDetails
where Salary NOT IN
(
SELECT TOP n-1 (EmpSalaryfrom tblEmployeeDetails ORDER BY EmpSalary Desc
) 

// 2nd
SELECT MAX(EmpSalary) as 'EmpSalary' from tblEmployeeDetails
where Salary NOT IN
(
SELECT TOP 1 (EmpSalary) from tblEmployeeDetails ORDER BY EmpSalary Desc
) 
Result-14000

// 3nd
SELECT MAX(EmpSalary) as 'EmpSalary' from tblEmployeeDetails
where Salary NOT IN
(
SELECT TOP 2 (EmpSalary) from tblEmployeeDetails ORDER BY EmpSalary Desc
)
 Result-13000

Saturday 15 November 2014

Get Controls type inside Gridview in asp.net code behind

//HTML
<asp:GridView ID="GridView1" runat="server" ></asp:GridView>

//C#
foreach (Control clt in GridView1.Rows[0].Controls)
                {
                    foreach (Control clt1 in clt.Controls)
                    {
                        if (clt1 is TextBox)
                        {
                            ((TextBox)clt1).BackColor = validateColor;
                        }
                        else if (clt1 is DropDownList)
                        {
                            ((DropDownList)clt1).BackColor = validateColor;
                        }
                    }
                }

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...