In this article I am going to show how we can use CASE in WHERE clause in SQL Server.
- ALTER PROCEDURE [dbo].[SearchEmployee]
- (
- @NAME VARCHAR(50)='',
- @City VARCHAR(50)='',
- @Joining_Date VARCHAR(50)=''
- )
- AS
- SELECT*FROM Emp_Information where
- NAME=case @NAME when''then NAME Else @NAME end
- ANDCONVERT(DATE,CONVERT(VARCHAR(10),Joining_Date, 101))=case @Joining_Date when''thenCONVERT(DATE,CONVERT(VARCHAR(10),Joining_Date, 101))Else @Joining_Date end
- AND City=case @City when''then City Else @City end
Now execute Stored Procedure,
Read more articles on SQL Server: