Saturday, May 28, 2011

How to use select case when clause in the .NET application

If they are static field of about 5-10 we can use this select case clause.Usually this is similiar to switch case in C# or C or C++.

Below is the syntax..

Case key Value
when 'string/Number' then 'static Values'
End

Example:

SELECT ename,

CASE empid WHEN 1 THEN 'Admin'
WHEN 2 THEN 'AccountManager'
WHEN 3 THEN 'HRManager'

END as EmployeesDetails from Emp_Table

Like the above we use the select case clause.