Introduction
Sometimes, depending on business requirements, we need to fetch all records if the search text parameter is blank. We have many ways to satisfy that requirement.
I have the following Employee Table in my SQL Server:
SELECT * FROM EMPLOYEE

CASE 1
Now if we pass a Search Parameter to select records from this table.
DECLARE @SEARCHTEXT VARCHAR(50)
SET @SEARCHTEXT='Ra'
SELECT * FROM EMPLOYEE WHERE NAME LIKE '%'+ ISNULL(@SEARCHTEXT, NAME) +'%'

Now set SearchText to null or blank.
DECLARE @SEARCHTEXT VARCHAR(50)
SET @SEARCHTEXT=''
SELECT * FROM EMPLOYEE WHERE NAME LIKE '%'+ ISNULL(@SEARCHTEXT, NAME) +'%'

Case 2
DECLARE @SEARCHTEXT VARCHAR(50)
SET @SEARCHTEXT=''
IF(LEN(@SEARCHTEXT)>0)
SELECT * FROM EMPLOYEE WHERE NAME=@SEARCHTEXT
ELSE
SELECT * FROM EMPLOYEE WHERE NAME= NAME

Summary
This article taught us how Return All Records If the Search Text is Blank in SQL Server.

Rahul Kumar SaxenaPosted Apr 23, 2015, 2:13 PM
Thanks Karthik Muthu Karuppan...
Karthik Muthu KaruppanPosted Apr 23, 2015, 11:19 AM
good one
Rahul Kumar SaxenaPosted Apr 22, 2015, 2:29 PM
Thanks Namit gupta...
Rahul Kumar SaxenaPosted Apr 22, 2015, 2:29 PM
Thanks Nitin tyagi...
Rahul Kumar SaxenaPosted Apr 22, 2015, 2:29 PM
Thanks Manoj Kulkarni...
NAMIT GUPTAPosted Apr 22, 2015, 6:10 AM
good one !
NitinPosted Apr 22, 2015, 5:53 AM
Nice
Manoj KulkarniPosted Apr 22, 2015, 4:06 AM
Thank you for sharing
Rahul Kumar SaxenaPosted Apr 21, 2015, 11:41 PM
Thanks Gowtham Rajamanickam
Gowtham RajamanickamPosted Apr 21, 2015, 11:26 PM
good one