Hi,
Please find the code sample for the search pattern you described.
go
Declare @Qry nvarchar(max)
Declare @Title varchar(150)
Declare @Description varchar(150) , @DescOpr varchar(10)
Declare @Location varchar(150) , @LocationOpr varchar(10)
Set @Title = 'Around the world'
set @Description = ''
Set @Location = 'Chennai'
set @LocationOpr = 'or'
Set @Qry = ' Select * from Books Where Isactive =1'
if (@Title <> '' )
Begin
set @Qry = @Qry + ' And Title = '''+ @Title + ''''
End
if (@Description <> '' and @DescOpr ='AND')
Begin
set @Qry = @Qry + ' And description ='''+ @Description + ''''
End
Else
Begin
set @Qry = @Qry + ' or description ='''+ @Description + ''''
End
if (@Location <> '' and @LocationOpr ='AND')
Begin
set @Qry = @Qry + ' And Location = '''+ @Location + ''''
End
Else
Begin
set @Qry = @Qry + ' or Location = '''+ @Location + ''''
End
print @Qry
exec (@Qry)
go
Hope this helps
Regards,
Mahe...