If you are filtering from 4 different Dropdownlist then there must be all condition you need to check whether you have selected any af dropdownvalue or not.
Refer the one simmiller example which might be helpful for you.
I am also filtering from Four different value which pass as parameter value to procedure .
Depending on value which i have selected it filtered the records.
By default the first item value is same as All . if user not select any value from dropdown it will filter it without checking value for column as first value is pass as 'ALL'.
-- EXEC EmployeeDetails_Filter 'All','ALL','All','All'
-- EXEC EmployeeDetails_Filter 'All','Amir','Mumbai','all'
-- EXEC EmployeeDetails_Filter '1','All','Mumbai','all'
ALTER Procedure EmployeeDetails_Filter
@EmployeeId Varchar(10)
,@Name Varchar(10)
,@City Varchar(10)
,@Country Varchar(10)
AS
BEGIN
Declare @SqlSelectstr Varchar(1000)
,@sqlWhereStr Varchar(1000)
SET @SqlSelectstr = 'Select * from EmployeeRecords'
SET @sqlWhereStr = ' '
IF @EmployeeId <> 'ALL'
BEGIN
SET @sqlWhereStr = ' EmployeeId IN ('+@EmployeeId+')'
END
IF @Name <> 'ALL'
IF @EmployeeId <> 'ALL'
BEGIN
SET @sqlWhereStr = @sqlWhereStr +' AND Name Like ''%'+ @Name + '%'''
END
ELSE
BEGIN
SET @sqlWhereStr = ' Name Like ''%'+@Name+'%'''
END
IF @City <> 'ALL'
IF @EmployeeId <> 'ALL' AND @Name <> 'ALL'
BEGIN
SET @sqlWhereStr = @sqlWhereStr +' AND City Like ''%'+ @City + '%'''
END
ELSE IF @EmployeeId <> 'ALL'
BEGIN
SET @sqlWhereStr = ' EmployeeId IN ('+@EmployeeId+') AND City Like ''%'+@City+'%'''
END
ELSE IF @Name <> 'ALL'
BEGIN
SET @sqlWhereStr = ' Name Like ''%'+@Name+'%'' AND City Like ''%'+@City+'%'''
END
ELSE
BEGIN
SET @sqlWhereStr = ' City Like ''%'+ @City + '%'''
END
IF @Country <> 'ALL'
IF @EmployeeId <> 'ALL' AND @Name <> 'ALL' AND @City <> 'ALL'
BEGIN
SET @sqlWhereStr = @sqlWhereStr +' AND Country Like ''%'+@Country+'%'''
END
ELSE IF @EmployeeId <> 'ALL' AND @Name <> 'ALL'
BEGIN
SET @sqlWhereStr = ' EmployeeId IN ('+@EmployeeId+') AND Name Like ''%'+@Name+ '%'' AND Country Like ''%'+@Country+'%'''
END
ELSE IF @EmployeeId <> 'ALL' AND @City <> 'ALL'
BEGIN
SET @sqlWhereStr = ' EmployeeId IN ('+@EmployeeId+') AND City Like ''%'+@City+'%'' AND Country Like ''%'+@Country+'%'''
END
ELSE IF @Name <> 'ALL' AND @City <> 'ALL'
BEGIN
SET @sqlWhereStr = ' Name Like ''%'+@Name+'%'' AND City Like ''%'+@City+'%'' AND Country Like ''%'+@Country+'%'''
END
ELSE IF @EmployeeId <> 'ALL'
BEGIN
SET @sqlWhereStr = ' EmployeeId IN ('+@EmployeeId+') AND Country Like ''%'+@Country+'%'''
END
ELSE IF @City <> 'ALL'
BEGIN
SET @sqlWhereStr = ' @City Like ''%'+@City+'%'' AND Country Like ''%'+@Country+'%'''
END
ELSE IF @Name <> 'ALL'
BEGIN
SET @sqlWhereStr = ' Name Like ''%'+@Name+'%'' AND Country Like ''%'+@Country+'%'''
END
ELSE
BEGIN
SET @sqlWhereStr = ' Country Like ''%'+@Country+'%'''
END
IF @EmployeeId <> 'ALL' OR @Name <> 'ALL' OR @City <>'ALL' OR @Country <> 'ALL'
BEGIN
SET @SqlSelectstr = @SqlSelectstr + ' Where ' + @sqlWhereStr
END
EXEC (@SqlSelectstr)
END