How to Search for Text inside PDF Files in SQL Serve part2 – Solution to Syntax error near '' in the full-text search condition '’ in Sql Server

Hi Guys, In my previous post
http://pnsoftwarestudies.blogspot.com/2017/03/how-to-search-for-text-inside-pdf-files.html

I had documented in detail on how to implement search inside pdf files, the full text query shared supported searching for a single word,  but when we try to search with multiple words, we will face below error as -

Msg 7630, Level 15, State 3, Line 40
Syntax error near 'are' in the full-text search condition 'brothers are'.

Syntax error near '' in the full-text search condition


So to support multiple keyword search we need to modify the query as below -
Declare @SearchKey varchar(200)
Set @SearchKey = '"brothers are"'
SELECT *
FROM dbo.DocumentsTable
WHERE contains([FileContent],@SearchKey);

The Stored procedure is as below - 
CREATE PROCEDURE [dbo].[sp_SearchForFile]
  @varSearchCriteriaIN    NVARCHAR(2000)= NULL,
  @varFromDateIN DateTime = NULL,
  @varToDateIN DateTime = NULL,
  @varFileTypeIN              NVARCHAR(max)= NULL
AS
  BEGIN
  SET NOCOUNT ON;
  SET @varSearchCriteriaIN = '"'+ @varSearchCriteriaIN  +'"'
  print @varSearchCriteriaIN
               SELECT * FROM dbo.DocumentsTable
               WHERE contains([FileContent],@varSearchCriteriaIN);



  END

No comments: