Pages

Wednesday, 21 August 2013

One-liner if statements, how to convert this if-else-statement

Syntax :
return (expression) ? value1 : value2;
If value1 and value2 are actually true and false like in your example, you may as well just

return expression;
or
<result> = <condition> ? <true result> : <false result>;
Example :
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";

Tuesday, 16 July 2013

Auto generated Try, Catch and Finally block in C#

Auto generated Try and Finally
tryf  -> press tab
                    try
                    {

                    }
                    finally
                    {


                    }


Auto generated Try and Catch
tryc ->press tab ->press tab 

                     try
                    {

                    }
                    catch (Exception)
                    {
                        
                        throw;

                    }

Friday, 29 March 2013

How to create duplicate table with new name in SQL Server 2008


How to create duplicate table with new name in SQL Server 2008

or How to copy or backup table

SELECT *
INTO new_table_name 
FROM old_tablename
Or we can select only the columns we want into the new table:
SELECT column_name(s)
INTO new_table_name 
FROM old_tablename
Example :
SELECT *
INTO Employee_Backup
FROM Employee
only columns:
SELECT LastName,FirstName
INTO Employee_Backup
FROM Employee

Thursday, 14 March 2013

Disable your back button


Code to disable your back button on logout page after logging out from page:

Place this code just above the head section of your master page source code(which contains your logout button) and/or also on a page wherever your logout button is placed.

<script type = "text/javascript" >
function disableBackButton() {
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>

Find Nth Highest Salary of Employee



The following solution is for getting 6th highest salary from Employee table ,

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

You can change and use it for getting nth highest salary from Employee table as follows

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)