How to use switch statement in c# ?

Switch statement is used to check a variable with a set of conditions called cases. We can check a variable whether the value satisfies certain conditions.
For example below I have checked a variable is A, B or C. in some case we need to do some operations according to the check then we can go for the switch case.

Syntax for switch statement in c#

switch(expression_data) {
case condition1 :
Method1(s);
break; /* optional */
case condition2 :
Method2(s);
break; /* optional */
.
.
.
.
.

default : /* Default is optional */
methodN(s);
}

Example for switch statement in c#

using System;
namespace FindVariable
{
class Program
{
static void Main(string[] args)
{
char character_variable = 'B';

switch (character_variable)
{
case 'A':
Console.WriteLine("Variable has value A");
break;
case 'B':
Console.WriteLine("Variable has value B");
break;
case 'C':
Console.WriteLine("Variable has value C");
break;

default:
Console.WriteLine("The variable not have the chartectors A,B and C");
break;
}
Console.WriteLine("The variable has value{0}", character_variable);
Console.ReadLine();
}
}
}

Output

Variable has value B
The variable has value B

Array in Javascript

Array is a variable that is used to hold more than one value in a single variable. That is we can hold a list of data inside an array.

How to declare an array in javascript ?

We can declare an array in two ways. these are the ways we can achieve it.

Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayName2 = ["data 1", "data 1", "data 3"];

How to add elements to array in javascript ?

Javascript array has a method push, the method we can use to add new elements to the array. when we use push the element will be added at the end of the array.
Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3
arrayName1.push("data 4");
var arrayNewLength=arrayName1.length; // output will be 4

How to delete an elements from array in javascript?

Javascript array has method named pop , it help us to delete an element from an array. when we use pop the elements at the end will be deleted.

Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3
arrayName1.pop();
var arrayNewLength=arrayName1.length; // output will be 2

How to find number of elements in an array in javascript ?

Javascript array has a property called length , the length property help us to find the number of elements exist in an array.
Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3

What is comments and types of comments in javascript?

                          For two reasons we can have comments in the code, one is to define the description of the specific code and the another thing is to prevent the execution of code .

There are two type of comments are available in javascript

1. Single line comment
2. Multiple line comment

Single line comment

Single line comment is used to comment a single line of code.

Syntax

//the code we need to comment

Example

// var total=0;

Multiple line comment

Multiple line comment is used to comment a block of coded that is multy line commenting.

Syntax

/*
the code we need to comment line 1
the code we need to comment line 2
the code we need to comment line 3
*/

Example

/*
var a=10;
var b=20;
var c=a+b;
*/

 

How to comment codes in TWIG ?

Whenever we write codes we may need to comment some codes to avoid displaying and executing the line.we need two ways of commenting , they are single line commenting and multi line commenting.

Single line commenting

Single line commenting is used to comment a line of code .

Syntax

{# Commented code #}

Example

{#   <h3>{{ heading_title }}</h3>   #}

Multi line commenting

Multi line commenting is used to comment a part of codes or multiple lines of codes. the syntax and way of commenting is same as of single line commenting for the multi line commenting.

Syntax

{# Commented code #}

Example

{#

{% if product %}
<span>{{ product.title }}</span>
{% endif %}

#}

How to find Nth highest salary in Sql Server ?

How to find Nth highest salary in Sql Server ?

Finding the first or second or Nth highest salary of the person is a most important thing for the developers, as a developer we should know this. Mostly we hear this question in the interview.

Consider the below table with table name Employee

SELECT * FROM [dbo].[Employee]

How to find highest salary in Sql Server?

There are so many ways to find highest salary, you can see below some of the examples

Method 1

select max(salary) as highest_salary from [dbo].[Employee]

Method 2

select top 1 salary as highest_salary from [dbo].[Employee] order by salary desc

Method 3

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary
FROM CTE
WHERE [Rank]=1;

How to 2nd highest salary in Sql Server?

We are seen some of the methods to find highest salary above, we cannot use method 1 and method 2 to find the 2nd highest salary, but we can use the method 1 by little change in the code.

There are so many ways to 2nd highest salary, you can see below some of the example

Method 1

SELECT MAX(salary) FROM Employee WHERE Salary NOT IN ( SELECT Max(Salary) FROM Employee);

Method 2

SELECT TOP 1 Salary FROM ( SELECT TOP 2 Salary FROM Employee ORDER BY Salary DESC) AS MyTable ORDER BY Salary ASC;

Method 3

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary FROM CTE WHERE [Rank]=2;

How to Nth highest salary in Sql Server?

Previously we have seen highest salary and 2nd highest salary solutions, also we know the query using CTE is used again used in 2nd highest salary with a little modification, the modification is we are changing the rank

If we want 1st highest salary we have to give rank as 1

If we want 2nd highest salary we have to give rank as 2

So we can use the same query to find the nth salary like below

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)

SELECT  salary as highest_salary FROM CTE WHERE [Rank]=”Nth”;

Example

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank] 
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary FROM CTE WHERE [Rank]=”Nth”;

Finding 5th highest salary in sql server

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary
FROM CTE WHERE [Rank]=5;

What are the main differences between DML vs DDL?

The main difference between DML vs DDL is – one for managing data in database and other for define database. DML stands for Data Manipulation Language and DDL stands for Data Definition Language.

    1. DML statements are used to manage the data in a database just like insert, update, delete etc.
      insert into table(col1, col2, col3) value(val1, val2, val3)
    2. DDL statements are used to create and define database structure just like create, alter, drop etc.
      create table tablename (col1 datatype, col2 datatype, col3 datatype)
    3. DML statements work with rows of data in table. For example, insert will create one or more rows in a table, where DDL works on database objects like table or views etc. For example, create will create a new object of table or view or procedure etc.
    4. Most of the DML support where clause and having clause for filtering data and order by and group by functions. But DDL does not support these functions.
    5. Transactions can be applied to DML statements. Which means, COMMIT and ROLLBACK are supported in DML statements. But DDL does not support Transactions. Which means once a table is created it cannot be roll backed. It need another DDL statement of DROP to remove the table from database.
    6. DDL statements cannot fire any triggers. But DML can fire triggers.

How to concat 2 strings without using any inbuilt string functions?

String is a character array.Find the length of the first character array, and find the length of the second character array, using a loop concat both strings.

Sample C# code :

string variable1 = “String concat”;
string variable2 = “example.”;
int length1 = variable1.Length;
int length2 = variable2.Length;
char[] concat = new char[length1 + length2];
for (int i = 0; i < length1; i++)
{
concat[i] = variable1[i];
}
for (int i = 0; i < length2; i++)
{
concat[i + length1] = variable2[i];
}

WHAT IS AJAX AND ITS FEATURES?

WHAT IS AJAX?

  • Asynchronous Javascript And Xml. It is not a programming language
  • Used to create better, faster and more interactive applications.
  • Ajax uses asynchronous data transfer between the browser and server.
  • Ajaxcontroltoolkit.dll is the dll used for Ajax control tool kit. 

What are the controls of ajax?

  • ScriptManager
  • ScriptManagerProxy
  • UpdatePanel
  • UpdateProgress
  • Timer

What are the advantages of AJAX?

  • It saves memory while fetching data from same page
  • More interactive
  • Speed 

What are the disadvantages of AJAX?

  • AJAX is dependent on javascript
  • Security issues
  • Debugging difficulty

What are the technologies used by AJAX?

  • Javascript
  • XMLHttpRequest
  • Document Object Model(DOM)
  • Extensible HTML(XHTML)
  • Cascading Style Sheets (CSS)

What are the features of AJAX?

  • Dataview control
  • Live data binding
  • Invoking Ado.net data services and data contexts
  • Client side template rendering

 

What is the difference between AJAX and JAVASCRIPT?

AJAX JAVASCRIPT
Ajax send request and performs other operations in the mean time they get the response Javascript send request and waits for the response
Full page downloading is not needed Full page downloading is needed
minimize the overload on server Posts request and updates the script every time
AJAX is a technique of communication Javascript is a scripting language

 

Joins in SQL

SQL JOINS

Joins in SQL are used to get related data from different tables. SQL joins are very useful feature in relational database while writing logical queries. There are different types of joins in SQL. They are

  • Inner Join (Join)
  • Outer Join
  • Cross Join
  • Self Join

Inner Join (Join)

Inner Join is used to retrieve only the matching records from both tables. The un-matching records will be omitted from result. The Join in SQL without any keywords like Inner, Outer, Left, Right or Cross is considered as Inner Join.

Outer Join

It retrieves either all rows from one table and only matching rows from other table or all rows from all tables. Doesn’t bother about matching. There are three kinds of outer join. They are.

Left Outer Join or Left Join

When we want all the rows from left table and only matching rows from right table, then we can use Left Outer or Left Join. If there is no matching records, it will return null values.

Right Outer Join or Right Join

When we need to fetch all the records from right table and only matching rows from left table, then we have to use Right outer or Right Join. If there is no matching rows in left table, then it will return null values.

Full Outer Join or Full Join

This combines both Left Outer join and Right Outer joins together. It returns records from both table when condition matches. If no match, then will show null. Concluding Outer Join, it can be said as it will return complete records from any of Left table or Right table and only matching from other table or from both(FULL) tables as matching together and not matching as null.

SQL JOINS
Types of JOINS in SQL

Cross Join

It is the Cartesian product of tables involved in join. Which means, each records from both tables will be combined to return result. This It is one of the least used join.

Self Join

Joining a table with itself is called Self Join It is mainly used with a table having hierarchy structure data in it like Employee Table with Manager_Id. Here Manager is also an employee and other employee will have a higher employee as manager. So in that situation, to get a manager of an employee, we need to join the same table with itself to get employee and manager. first table will act as employee table and second joining will act as Manager table.

Joins in SQL Based on Operators

Based on the operator used for joining tables, it can be classified into two types.

Equi Join

If we use only the = in join clause, then it is called Equi Join

Theta Join

When we use operators like >, <, >=, <= is known as Theta Join