Thank you Khtan... I rectified this problem with dynamic query...
ALTER procedure [search_fields]
(
@drpSelectValue VARCHAR(50) = null,
@txtValue as varchar(10)=null
)
As
begin
DECLARE @SQL varchar(max) =''
if @drpSelectValue = 'username'
begin
SET @SQL = 'select * from Userdetails where ' + @drpSelectValue +' like (case when '''+@txtValue +''' is not null then '''+ @txtValue+ '%'' else ' + @drpSelectValue +' end)'
end
else
Begin
SET @SQL = 'select * from Userdetails where ' + @drpSelectValue +' = (case when '''+@txtValue +''' is not null then '''+ @txtValue+ ''' else ' + @drpSelectValue +' end)'
End
EXEC (@SQL)
End
GO
exec search_fields 'username', 'king'
exec search_fields 'username', null -- Problem
There is one more problem when i pass NULL to @txtValue..
--
Chandu