Case Statement in SQL Server


Case statement in SQL Server is a very handy one to showcase your output as expected or for customising your output,  you can use Case statement. Please find a small example to get use of the case statement.

 

DROP
TABLE VENKAT_TABLE
GO
CREATE
TABLE VENKAT_TABLE(ID INT, NAME VARCHAR(100),MARKS INT)
INSERT
INTO VENKAT_TABLE VALUES (1,'VENKAT',20)
INSERT
INTO VENKAT_TABLE VALUES (2,'SUBA',80)
INSERT
INTO VENKAT_TABLE VALUES (3,'LAKSHMI',45)
INSERT
INTO VENKAT_TABLE VALUES (4,'SANTHI',70)
SELECT
ID, NAME,
CASE WHEN MARKS >50 THEN 'GOOD'
ELSE 'BAD'
END

AS RESULT
FROM VENKAT_TABLE

The output is,

1.jpg
Cheers,
Venkatesan prabu .J
http://venkattechnicalblog.blogspot.com/
 http://www.kaashivinfotech.com/