Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




.NET and SQl Server interview questions :- Testing of SQL CASE syntax capability with complicated SQL query.

Answer:

Let's us assume that we have the following table of Employee.

Emp_Id

Emp_Name

Emp_Salary

1

Shiv

17000

2

Raju

13500

3

Sham

15000

4

Moosa

11000

5

Firoz

12000

There can be a scenario we have to display employee name whose salary is greater than "some amount" or less than "some amount" for that purpose we use case statement.

Let's us consider that we have to display all the employee names from the employee table and the status like salary is greater than 13000 or lesser than 13000.

Query:

 SELECT Emp_Name,CASE
 when (Emp_Salary>13000) then 'Greater than 13000'
 else 'Lesser than 13000'
 end as Status
 FROM Employee

Output:

Emp_Name

Status

Shiv

Greater than 13000

Raju

Greater than 13000

Sham

Greater than 13000

Moosa

Lesser than 13000

Firoz

Lesser than 13000

Hence you can see that all the employee name have been displayed with their salary status in the above output.
 

Please click here to see more .NET and SQl Server interview questions

Regards,

Visit Authors blog for more .NET and SQL Server interview questions

Share this article   |    Print    |    Article read by 3547 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question