Case statement acts like an If-Else statement in stored procedure. It will modify the name of the data, which is not actual data in the table.
Description
Case statement is mostly used in real time scenarios. Sometimes it is based on Id of a table's column value. You can mention the list of names in the dropdown binding list using case statement in T-SQL.
Steps to follow
Create one table.
- CREATE TABLE tblDepartment1
- (
- DeptId int Primary Key,
- DeptName nvarchar(20)
- )
- Insert into tblDepartment1 values (1,'Blog')
- Insert into tblDepartment1 values (2,'Article')
- Insert into tblDepartment1 values (3,'Resource')
- Insert into tblDepartment1 values (4,'Book')
- Create procedure Sp_CaseStatement
- As
- Begin
- set NoCount ON;
- select case tbldepartment1.deptname when 'Blog' Then 'Blog(400)'
- when 'Article' Then 'Article(100)'
- when 'Resource' Then 'Resource(200)'
- when 'Book' Then 'Book(300)'
- else 'UnKnown' end as 'Your Contribution Counts'
- from tbldepartment1
- end
- Select * from tblDepartment1
- exec Sp_CaseStatement
Summary
- What is case statement, using stored procedure?
- How to implement, using stored procedure in real time scenario.

Join the conversation! Your thoughts help the community grow.