Friday, March 23, 2012

Switch and Case in C# and SQL Formats


IN C# We can Write As
 fallows:

int connectionFormat=0;
string strConnectionType="WebSite";

switch (strConnectionType)
{
case "Phone":
connectionFormat = 0;
break;
case "Email":
connectionFormat = 1;
break;
case "WebSite":
connectionFormat = 2;
break;
case "Others":
connectionFormat = 3;
break;
default:
connectionFormat = 0;
break;
}

------
OutPut :
connectionFormat=2
 
-----------

SQL Server Statement
------------------

SELECT
CASE
WHEN C.Connectionformat = 0 THEN 'Phone'
WHEN C.Connectionformat = 1 THEN 'Email'
WHEN C.Connectionformat = 2 THEN 'Website'
WHEN C.ConnectionFormat =3 THEN 'Others'
END AS ConnectionType,
C.Value AS Information
FROM Connection C


OutPut::

Phone 121212
Email a@annet.com
Website www.annet.com
Phone 765432
Email b@annet.com
Phone 667877
Email b@annet.com

 

No comments: